Created
March 20, 2018 21:22
-
-
Save yhay81/aaba25db98e8adcfb4f44bf2960230d8 to your computer and use it in GitHub Desktop.
Python speed test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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