-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimers.py
More file actions
31 lines (25 loc) · 690 Bytes
/
timers.py
File metadata and controls
31 lines (25 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
Created on Jan 2, 2016
@author: ddorroh,jglover
'''
import time
class timewith():
'''
:see: https://zapier.com/engineering/profiling-python-boss/
'''
def __init__(self, name=''):
self.name = name
self.start = time.time()
@property
def elapsed(self):
return time.time() - self.start
def checkpoint(self, name=''):
print '{timer} {checkpoint} took {elapsed} seconds'.format(
timer=self.name,
checkpoint=name,
elapsed=self.elapsed,
).strip()
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.checkpoint('finished')