Created
October 22, 2014 20:50
-
-
Save bsmithgall/fb8f24df0c1cb03b09d4 to your computer and use it in GitHub Desktop.
Time it for eva
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
# Big thanks to @deacondesperado | |
class Timer(): | |
def __enter__(self): | |
self.start = time.clock() | |
return self | |
def __exit__(self, *args): | |
self.end = time.clock() | |
self.interval = self.end - self.start | |
def timeit(func): | |
@functools.wraps(func) | |
def with_timer(*args, **kwargs): | |
with Timer() as t: | |
val = func(*args, **kwargs) | |
print '{name}: {time}'.format(name=func.__name__, time=t.interval) | |
return val | |
return with_timer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment