Skip to content

Instantly share code, notes, and snippets.

@wbbradley
Created July 15, 2014 06:18
Show Gist options
  • Save wbbradley/ab938411dc5dbb51a77f to your computer and use it in GitHub Desktop.
Save wbbradley/ab938411dc5dbb51a77f to your computer and use it in GitHub Desktop.
import time
class Timer(object):
def __init__(self, name):
self.name = name
def __enter__(self):
self.start = time.clock()
return self
def __exit__(self, *args):
self.end = time.clock()
self.interval = self.end - self.start
print '%s took %.03f sec.' % (self.name, self.interval)
def __call__(self, f):
def wrapped_f(*args, **kwargs):
with self:
return f(*args, **kwargs)
return wrapped_f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment