-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
60 lines (42 loc) · 1.22 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
from timerdec.decorators import timerdec, timerdec_always, nowdec
from timerdec.snapshots import now
import time
import numpy as np
#We can require timing information collection for function r at run time.
@timerdec()
def r(size1, size2):
return np.random.rand(size1, size2)
class cl():
def __init__(self):
pass
#We can require timing information collection for method f at run time. A progress bar will be printed
@timerdec(progress=True)
def f(self):
a = r(1000, 1000)
b = r(1000, 1000)
c = np.dot(a,b)
#Timing information will always be collected for this method. Method is run 1000 times
@timerdec_always(1000)
def dummy(self, a):
pass
c = cl()
def do():
c.f()
c.dummy(a="dummy data")
now('before do')
do()
now('after do')
def ultima(s):
time.sleep(1)
return s
#We can also wrap function calls
res1 = timerdec_always()(ultima)("Hello!")
print(res1)
#Subsequent calls of functions with inline (non decorator) wrapping will not be object of measures
res2 = ultima('Bye!')
print(res2)
vec = np.zeros((1000,1000))
now()
#It is possible to inline wrap object methods as well
res3 = timerdec_always()(vec.astype)(np.uint8)
now()