Skip to content

Instantly share code, notes, and snippets.

@yhay81
Created March 20, 2018 21:22
Show Gist options
  • Save yhay81/aaba25db98e8adcfb4f44bf2960230d8 to your computer and use it in GitHub Desktop.
Save yhay81/aaba25db98e8adcfb4f44bf2960230d8 to your computer and use it in GitHub Desktop.
Python speed test
from functools import wraps
from time import time
def timing(f):
@wraps(f)
def wrapper(*args, **kwds):
s = time()
f(*args, **kwds)
return time() - s
return wrapper
def repeat(count):
def _r(f):
@wraps(f)
def wrapper(*args, **kwds):
for _ in range(count):
f(*args, **kwds)
return wrapper
return _r
def compare(f1, f2, count=100):
times = [[f1(), f2()] for _ in range(count)]
result = tuple(map(sum, zip(*times)))
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment