-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
53 lines (37 loc) · 790 Bytes
/
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
from average import average
import numpy as np
import time
a = np.ones((1000000,), dtype = np.float32)
start = time.time()
result = average.average(a)
end = time.time()
print end - start
b = list(range(1000000))
start = time.time()
_sum = 0
for item in b:
_sum += item
result = _sum / len(b)
end = time.time()
print end - start
start = time.time()
result = sum(b) / len(b)
end = time.time()
print end - start
start = time.time()
result = reduce(lambda x, y: x + y, b)
end = time.time()
print end - start
start = time.time()
result = [item * 2 for item in b]
end = time.time()
print end - start
start = time.time()
for idx, item in enumerate(b):
b[idx] = 2 * item
end = time.time()
print end - start
start = time.time()
a = 2. * a
end = time.time()
print end - start