-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.py
More file actions
50 lines (34 loc) · 901 Bytes
/
components.py
File metadata and controls
50 lines (34 loc) · 901 Bytes
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
import sys
import time
def add(n: int) -> int:
result = 0
for i in range(n):
result += (i + 1)
return result
def mul(n: int) -> None:
# Run many times to get longer execution period
for x in range(4000000):
result = 1
for i in range(n):
result *= (i + 1)
return result
def mul_with_time(q1, q2) -> int:
round = 0
while True and round < 2:
n = q1.get()
start = time.time()
q2.put(mul(n))
round += 1
end = time.time()
sys.stderr.write(f'Time cost for mul {end - start}\n')
sys.stderr.flush()
def add_with_time(q) -> int:
round = 0
while True and round < 2:
n = q.get()
start = time.time()
add(n)
round += 1
end = time.time()
sys.stderr.write(f'Time cost for mul {end - start}\n')
sys.stderr.flush()