-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (46 loc) · 1.82 KB
/
Copy pathmain.py
File metadata and controls
79 lines (46 loc) · 1.82 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import Process
from threading import Thread
import os
import time
# starts pool execution clock **************************************************************************************
start_pool = time.time()
def thread_pool():
for _ in range(50000000):
beta = 0
executor = ThreadPoolExecutor(max_workers=os.cpu_count())
executor.submit(thread_pool())
print(f'ThreadPool execution time: {round(float(time.time() - start_pool), 2)} seconds')
# starts process execution clock **************************************************************************************
start_process = time.time()
def process_function():
for _ in range(50000000):
alpha = 0
processes = []
for _ in range(os.cpu_count()):
processes.append(Process(target=process_function))
for process in processes:
process.start()
for process in processes:
process.join()
print(f'Process execution time: {round(float(time.time() - start_process), 2)} seconds')
# starts thread execution clock **************************************************************************************
start_thread = time.time()
def thread_function():
for _ in range(50000000):
beta = 0
threads = []
for _ in range(os.cpu_count()):
threads.append(Thread(target=thread_function))
for thread in threads:
thread.start()
for thread in threads:
thread.join()
print(f'Thread execution time: {round(float(time.time() - start_thread), 2)} seconds')
# starts normal execution clock **************************************************************************************
start_general = time.time()
def normal_function():
for _ in range(50000000):
beta = 0
normal_function()
print(f'Normal execution time: {round(float(time.time() - start_general), 2)} seconds')