-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.py
47 lines (34 loc) · 804 Bytes
/
timer.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
This script provides utilities for time measurement.
"""
import time
class Timer():
def __init__(self):
self.fTotal = 0.0
return
def start(self):
self.fStart = time.time()
return
def stop(self):
fDelta = time.time() - self.fStart
self.fTotal += fDelta
print("Execution time: %3.2f sec" % fDelta)
return fDelta
def sum(self):
fTotal = self.fTotal
print("Total execution time: %3.2f sec" % fTotal)
self.fTotal = 0.0
return fTotal
def unittest():
timer = Timer()
timer.start()
for i in range(100):
print(i)
timer.stop()
timer.start()
for i in range(20):
print(i)
timer.stop()
timer.sum()
if __name__ == '__main__':
unittest()