forked from openai/human-eval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_multiprocessing.py
42 lines (32 loc) · 1.06 KB
/
test_multiprocessing.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
import multiprocessing as mp
import time
import math
results_a = []
results_b = []
results_c = []
def make_calculation_one(numbers):
for number in numbers:
results_a.append(math.sqrt(number**3))
def make_calculation_two(numbers):
for number in numbers:
results_b.append(math.sqrt(number**4))
def make_calculation_three(numbers):
for number in numbers:
results_c.append(math.sqrt(number**5))
if __name__ == "__main__":
number_list = list(range(2000000))
p1 = mp.Process(target=make_calculation_one, args=(number_list,))
p2 = mp.Process(target=make_calculation_two, args=(number_list,))
p3 = mp.Process(target=make_calculation_three, args=(number_list,))
start = time.time()
p1.start()
p2.start()
p3.start()
end = time.time()
print("Time taken in seconds -", end - start)
start_time = time.time()
make_calculation_one(number_list)
make_calculation_two(number_list)
make_calculation_three(number_list)
end_time = time.time()
print("Time taken in seconds -", end_time - start_time)