22# Simple benchmarks for the multiprocessing package
33#
44
5- import time , sys , multiprocessing , threading , Queue , gc
5+ import time , sys , multiprocessing , threading , queue , gc
66
77if sys .platform == 'win32' :
88 _timer = time .clock
@@ -20,7 +20,7 @@ def queuespeed_func(q, c, iterations):
2020 c .notify ()
2121 c .release ()
2222
23- for i in xrange (iterations ):
23+ for i in range (iterations ):
2424 q .put (a )
2525
2626 q .put ('STOP' )
@@ -48,8 +48,8 @@ def test_queuespeed(Process, q, c):
4848
4949 p .join ()
5050
51- print iterations , 'objects passed through the queue in' , elapsed , 'seconds'
52- print 'average number/sec:' , iterations / elapsed
51+ print ( iterations , 'objects passed through the queue in' , elapsed , 'seconds' )
52+ print ( 'average number/sec:' , iterations / elapsed )
5353
5454
5555#### TEST_PIPESPEED
@@ -60,7 +60,7 @@ def pipe_func(c, cond, iterations):
6060 cond .notify ()
6161 cond .release ()
6262
63- for i in xrange (iterations ):
63+ for i in range (iterations ):
6464 c .send (a )
6565
6666 c .send ('STOP' )
@@ -90,8 +90,8 @@ def test_pipespeed():
9090 elapsed = _timer () - t
9191 p .join ()
9292
93- print iterations , 'objects passed through connection in' ,elapsed ,'seconds'
94- print 'average number/sec:' , iterations / elapsed
93+ print ( iterations , 'objects passed through connection in' ,elapsed ,'seconds' )
94+ print ( 'average number/sec:' , iterations / elapsed )
9595
9696
9797#### TEST_SEQSPEED
@@ -105,13 +105,13 @@ def test_seqspeed(seq):
105105
106106 t = _timer ()
107107
108- for i in xrange (iterations ):
108+ for i in range (iterations ):
109109 a = seq [5 ]
110110
111111 elapsed = _timer ()- t
112112
113- print iterations , 'iterations in' , elapsed , 'seconds'
114- print 'average number/sec:' , iterations / elapsed
113+ print ( iterations , 'iterations in' , elapsed , 'seconds' )
114+ print ( 'average number/sec:' , iterations / elapsed )
115115
116116
117117#### TEST_LOCK
@@ -125,14 +125,14 @@ def test_lockspeed(l):
125125
126126 t = _timer ()
127127
128- for i in xrange (iterations ):
128+ for i in range (iterations ):
129129 l .acquire ()
130130 l .release ()
131131
132132 elapsed = _timer ()- t
133133
134- print iterations , 'iterations in' , elapsed , 'seconds'
135- print 'average number/sec:' , iterations / elapsed
134+ print ( iterations , 'iterations in' , elapsed , 'seconds' )
135+ print ( 'average number/sec:' , iterations / elapsed )
136136
137137
138138#### TEST_CONDITION
@@ -141,7 +141,7 @@ def conditionspeed_func(c, N):
141141 c .acquire ()
142142 c .notify ()
143143
144- for i in xrange (N ):
144+ for i in range (N ):
145145 c .wait ()
146146 c .notify ()
147147
@@ -162,7 +162,7 @@ def test_conditionspeed(Process, c):
162162
163163 t = _timer ()
164164
165- for i in xrange (iterations ):
165+ for i in range (iterations ):
166166 c .notify ()
167167 c .wait ()
168168
@@ -171,8 +171,8 @@ def test_conditionspeed(Process, c):
171171 c .release ()
172172 p .join ()
173173
174- print iterations * 2 , 'waits in' , elapsed , 'seconds'
175- print 'average number/sec:' , iterations * 2 / elapsed
174+ print ( iterations * 2 , 'waits in' , elapsed , 'seconds' )
175+ print ( 'average number/sec:' , iterations * 2 / elapsed )
176176
177177####
178178
@@ -181,51 +181,51 @@ def test():
181181
182182 gc .disable ()
183183
184- print '\n \t ######## testing Queue.Queue\n '
185- test_queuespeed (threading .Thread , Queue .Queue (),
184+ print ( '\n \t ######## testing Queue.Queue\n ' )
185+ test_queuespeed (threading .Thread , queue .Queue (),
186186 threading .Condition ())
187- print '\n \t ######## testing multiprocessing.Queue\n '
187+ print ( '\n \t ######## testing multiprocessing.Queue\n ' )
188188 test_queuespeed (multiprocessing .Process , multiprocessing .Queue (),
189189 multiprocessing .Condition ())
190- print '\n \t ######## testing Queue managed by server process\n '
190+ print ( '\n \t ######## testing Queue managed by server process\n ' )
191191 test_queuespeed (multiprocessing .Process , manager .Queue (),
192192 manager .Condition ())
193- print '\n \t ######## testing multiprocessing.Pipe\n '
193+ print ( '\n \t ######## testing multiprocessing.Pipe\n ' )
194194 test_pipespeed ()
195195
196- print
196+ print ()
197197
198- print '\n \t ######## testing list\n '
199- test_seqspeed (range (10 ))
200- print '\n \t ######## testing list managed by server process\n '
201- test_seqspeed (manager .list (range (10 )))
202- print '\n \t ######## testing Array("i", ..., lock=False)\n '
203- test_seqspeed (multiprocessing .Array ('i' , range (10 ), lock = False ))
204- print '\n \t ######## testing Array("i", ..., lock=True)\n '
205- test_seqspeed (multiprocessing .Array ('i' , range (10 ), lock = True ))
198+ print ( '\n \t ######## testing list\n ' )
199+ test_seqspeed (list ( range (10 ) ))
200+ print ( '\n \t ######## testing list managed by server process\n ' )
201+ test_seqspeed (manager .list (list ( range (10 ) )))
202+ print ( '\n \t ######## testing Array("i", ..., lock=False)\n ' )
203+ test_seqspeed (multiprocessing .Array ('i' , list ( range (10 ) ), lock = False ))
204+ print ( '\n \t ######## testing Array("i", ..., lock=True)\n ' )
205+ test_seqspeed (multiprocessing .Array ('i' , list ( range (10 ) ), lock = True ))
206206
207- print
207+ print ()
208208
209- print '\n \t ######## testing threading.Lock\n '
209+ print ( '\n \t ######## testing threading.Lock\n ' )
210210 test_lockspeed (threading .Lock ())
211- print '\n \t ######## testing threading.RLock\n '
211+ print ( '\n \t ######## testing threading.RLock\n ' )
212212 test_lockspeed (threading .RLock ())
213- print '\n \t ######## testing multiprocessing.Lock\n '
213+ print ( '\n \t ######## testing multiprocessing.Lock\n ' )
214214 test_lockspeed (multiprocessing .Lock ())
215- print '\n \t ######## testing multiprocessing.RLock\n '
215+ print ( '\n \t ######## testing multiprocessing.RLock\n ' )
216216 test_lockspeed (multiprocessing .RLock ())
217- print '\n \t ######## testing lock managed by server process\n '
217+ print ( '\n \t ######## testing lock managed by server process\n ' )
218218 test_lockspeed (manager .Lock ())
219- print '\n \t ######## testing rlock managed by server process\n '
219+ print ( '\n \t ######## testing rlock managed by server process\n ' )
220220 test_lockspeed (manager .RLock ())
221221
222- print
222+ print ()
223223
224- print '\n \t ######## testing threading.Condition\n '
224+ print ( '\n \t ######## testing threading.Condition\n ' )
225225 test_conditionspeed (threading .Thread , threading .Condition ())
226- print '\n \t ######## testing multiprocessing.Condition\n '
226+ print ( '\n \t ######## testing multiprocessing.Condition\n ' )
227227 test_conditionspeed (multiprocessing .Process , multiprocessing .Condition ())
228- print '\n \t ######## testing condition managed by a server process\n '
228+ print ( '\n \t ######## testing condition managed by a server process\n ' )
229229 test_conditionspeed (multiprocessing .Process , manager .Condition ())
230230
231231 gc .enable ()
0 commit comments