1import time
2from multiprocessing import Process
3
4# My functions (threads)
5def my_func_1():...
6def my_func_2():...
7
8# Single calculation
9start = time.time()
10my_func_1()
11my_func_2()
12print(f'Single thread total time: {time.time() - start}')
13
14# Processes
15process = Process(target=my_func_1)
16process2 = Process(target=my_func_2)
17process.start()
18process2.start()
19
20start = time.time() # Start the two processes
21
22process.join() # Wait till processes finish
23process2.join()
24
25print(f'Two thread total time: {time.time() - start}')
1from multiprocessing import Pool
2
3def test( v ):
4 print(v)
5 return v
6
7if __name__ == '__main__':
8 with Pool(2) as p:
9 print(p.map(test, range(5)))