-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocesses.py
More file actions
33 lines (25 loc) · 776 Bytes
/
processes.py
File metadata and controls
33 lines (25 loc) · 776 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
import time
from multiprocessing import Process
def ask_user():
start = time.time()
user_input = input('Enter your name: ')
greet = f'Hello, {user_input}'
print(greet)
print(f'ask_user', time.time() - start)
def complex_calculation():
start = time.time()
print('Started calculating......')
[x**2 for x in range(20000000)]
print(f'complex_calculation', time.time() - start)
start = time.time()
ask_user()
complex_calculation()
print(f'Single thread total time:', time.time() - start)
process = Process(target=complex_calculation)
process2 = Process(target=complex_calculation)
process.start()
process2.start()
start = time.time()
process.join()
process2.join()
print(f'Single thread total time:', time.time() - start, '\n\n')