12
12
13
13
We didn't break out worker setup time from computation time.
14
14
In 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
20
23
such as waiting for network connections, where coroutines and/or threads are often a better choice.
21
24
"""
22
25
@@ -62,7 +65,7 @@ def run(self):
62
65
63
66
64
67
def mp_worker (i : int , Niter : int , tic : float ):
65
- """ multiprocessing worker"""
68
+ """multiprocessing worker"""
66
69
for _ in range (Niter ):
67
70
math .sin (3 )
68
71
@@ -78,7 +81,10 @@ def mp_worker(i: int, Niter: int, tic: float):
78
81
)
79
82
P .add_argument ("-Nworker" , help = "number of workers" , type = int , default = 4 )
80
83
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 ,
82
88
)
83
89
A = P .parse_args ()
84
90
0 commit comments