1212
1313We didn't break out worker setup time from computation time.
1414In real-world situations, coroutines can be faster and less resource-consuming than threads.
15- There is no one best choice for all task types, we fit the asynchronous architecture to the task.
16- There are numerous other popular implementations of threading and coroutines beyond the built-in modules used here.
17-
18- In computation-bound programs like this example, coroutines and threads would generally not be as good a choice
19- as multiprocessing. However, the heavier resource usage of multiprocessing is not necessarily best for IO-bound tasks
15+ There is no one best choice for all task types,
16+ we fit the asynchronous architecture to the task.
17+ There are numerous other popular implementations of threading and coroutines
18+ beyond the built-in modules used here.
19+
20+ In computation-bound programs like this example, coroutines and threads would
21+ generally not be as good a choice as multiprocessing.
22+ However, the heavier resource usage of multiprocessing is not necessarily best for IO-bound tasks
2023such as waiting for network connections, where coroutines and/or threads are often a better choice.
2124"""
2225
@@ -62,7 +65,7 @@ def run(self):
6265
6366
6467def mp_worker (i : int , Niter : int , tic : float ):
65- """ multiprocessing worker"""
68+ """multiprocessing worker"""
6669 for _ in range (Niter ):
6770 math .sin (3 )
6871
@@ -78,7 +81,10 @@ def mp_worker(i: int, Niter: int, tic: float):
7881 )
7982 P .add_argument ("-Nworker" , help = "number of workers" , type = int , default = 4 )
8083 P .add_argument (
81- "-Niter" , help = "number of loop iterations (arbitrary)" , type = int , default = 5000000 ,
84+ "-Niter" ,
85+ help = "number of loop iterations (arbitrary)" ,
86+ type = int ,
87+ default = 5000000 ,
8288 )
8389 A = P .parse_args ()
8490
0 commit comments