Created
June 17, 2012 14:42
-
-
Save eliben/2944722 to your computer and use it in GitHub Desktop.
Timer utility
This file contains 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
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