-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiming.py
32 lines (26 loc) · 855 Bytes
/
timing.py
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
32
import time
class Timer:
"""Encapsulate performance timing"""
def __init__(self):
self.prevTime = 0
def reset_time(self):
self.prevTime = time.time()
def log_time(self, log_str):
currTime = time.time()
print(log_str + ' completed in: ' + str(currTime-self.prevTime))
self.prevTime = currTime
pass
def time_func(input_func):
"""Print out timing details of function. Use as a decorator (@time_func)"""
def timed(*args, **kwargs):
start_time = time.time()
result = input_func(*args, **kwargs)
end_time = time.time()
print('Method Name - {0}, Args - {1}, Kwargs - {2}, Execution Time - {3}'.format(
input_func.__name__,
args,
kwargs,
end_time - start_time
))
return result
return timed