Skip to content

Instantly share code, notes, and snippets.

@eliben
Created June 17, 2012 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliben/2944722 to your computer and use it in GitHub Desktop.
Save eliben/2944722 to your computer and use it in GitHub Desktop.
Timer utility
class Timer(object):
def __init__(self, name=None):
self.name = name
def __enter__(self):
self.tstart = time.time()
def __exit__(self, type, value, traceback):
if self.name:
print('[%s]' % self.name, end=' ')
print('Elapsed: %s' % (time.time() - self.tstart))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment