-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo.py
50 lines (41 loc) · 1.26 KB
/
demo.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
48
49
50
from lauda import StopWatch, stopwatch, stopwatchcm
def stopwatch_sum_cb(watch, function):
print ('Time spent inside {0} is {1} sec.'.format(function, watch.elapsed_time))
def stopwatch_sum_cb_w_cm(watch):
print ('Time spent is {0} sec.'.format(watch.elapsed_time))
@stopwatch(callback=stopwatch_sum_cb)
def awesome_sum(a, b):
return a + b
@stopwatch
def awesome_mul(a, b):
return a * b
@stopwatch
def awesome_print():
print 'Hello Niki!'
print awesome_sum(5, 10)
print awesome_mul(5, 10)
awesome_print()
watch = StopWatch()
watch.start()
for i in range(100000):
pass
print ('Time is running out.. {0} sec.'.format(watch.elapsed_time))
for i in range(10000000):
pass
watch.stop()
print ('Time spent in range: {0} sec.'.format(watch.elapsed_time))
with stopwatchcm(callback=stopwatch_sum_cb_w_cm):
c = 5 * 10
watch = StopWatch()
watch.start()
for i in range(10000000):
pass
print ('Time spent in first range: {0} sec.'.format(watch.checkpoint()))
for i in range(10000000):
pass
print ('Time spent in second range: {0} sec.'.format(watch.checkpoint()))
for i in range(10000000):
pass
print ('Time spent in third range: {0} sec.'.format(watch.checkpoint()))
watch.stop()
print ('Time spent in range total: {0} sec.'.format(watch.elapsed_time))