Skip to content

Instantly share code, notes, and snippets.

@bsmithgall
Created October 22, 2014 20:50
Show Gist options
  • Save bsmithgall/fb8f24df0c1cb03b09d4 to your computer and use it in GitHub Desktop.
Save bsmithgall/fb8f24df0c1cb03b09d4 to your computer and use it in GitHub Desktop.
Time it for eva
# 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