Last active
October 5, 2016 04:34
-
-
Save gtalarico/5406f750958123c7cb81cee9f0cd299a to your computer and use it in GitHub Desktop.
Simple Timer Class
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): | |
"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