fog/experiments/utils.py

14 lines
335 B
Python
Raw Normal View History

2018-06-20 09:39:21 +00:00
from timeit import default_timer as timer
class Timer(object):
2018-06-22 13:39:12 +00:00
def __init__(self, name='Timer'):
self.name = name
2018-06-20 09:39:21 +00:00
def __enter__(self):
self.start = timer()
def __exit__(self, *args):
self.end = timer()
self.duration = self.end - self.start
2018-06-22 13:39:12 +00:00
print('%s:' % self.name, self.duration)