Skip to content

Instantly share code, notes, and snippets.

@gtalarico
Last active October 5, 2016 04:34
Show Gist options
  • Save gtalarico/5406f750958123c7cb81cee9f0cd299a to your computer and use it in GitHub Desktop.
Save gtalarico/5406f750958123c7cb81cee9f0cd299a to your computer and use it in GitHub Desktop.
Simple Timer Class
class Timer(object):
"Time and TimeIt Decorator"
def __init__(self):
self.start_time = time.time()
def stop(self):
end_time = time.time()
duration = end_time - self.start_time
return duration
@staticmethod
def time_function(name):
def wrapper(func):
def wrap(*ags):
logger.debug('START: {}'.format(name))
t = Timer()
rv = func(*ags)
duration = t.stop()
logger.debug('Done: {} sec'.format(duration))
return rv
return wrap
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment