Skip to content

Instantly share code, notes, and snippets.

@mzizzi
Created November 14, 2015 19:58
Show Gist options
  • Save mzizzi/7208f21481cc7b3c72f8 to your computer and use it in GitHub Desktop.
Save mzizzi/7208f21481cc7b3c72f8 to your computer and use it in GitHub Desktop.
benchmark key presses on from aenea client to server
from aenea.wrappers import ensure_execution_context
from aenea import Key
import time
time.sleep(5)
# get context ahead of time so our timing is more accurate
DATA = ensure_execution_context({})
def press_separate():
action = Key('a-1') + Key('a-2') + Key('a-3') + Key('a-4') + Key('a-5')
action.execute(data=DATA)
def press_combined():
action = Key('a-1,a-2,a-3,a-4,a-5')
action.execute(data=DATA)
def press_repeat():
action = Key('a-1:5')
action.execute(data=DATA)
def bench(func, count=100):
t = time.time()
for _ in range(0, count):
func()
t = time.time() - t
return t / count
print 'running benchmarks...'
print 'press_separate execution time: %.4f' % bench(press_separate)
print 'press_combined execution time: %.4f' % bench(press_combined)
print 'press_repeat execution time: %.4f' % bench(press_repeat)
print 'done!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment