mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
2to3 run of multiprocessing examples.
mp_benchmarks, mp_newtypes and mp_distribution are still broken but the others are working properly. We should include the examples in our unit test suite ...
This commit is contained in:
parent
94e0772989
commit
aae1b70a83
6 changed files with 177 additions and 177 deletions
|
|
@ -2,7 +2,7 @@
|
|||
# Simple benchmarks for the multiprocessing package
|
||||
#
|
||||
|
||||
import time, sys, multiprocessing, threading, Queue, gc
|
||||
import time, sys, multiprocessing, threading, queue, gc
|
||||
|
||||
if sys.platform == 'win32':
|
||||
_timer = time.clock
|
||||
|
|
@ -20,7 +20,7 @@ def queuespeed_func(q, c, iterations):
|
|||
c.notify()
|
||||
c.release()
|
||||
|
||||
for i in xrange(iterations):
|
||||
for i in range(iterations):
|
||||
q.put(a)
|
||||
|
||||
q.put('STOP')
|
||||
|
|
@ -48,8 +48,8 @@ def test_queuespeed(Process, q, c):
|
|||
|
||||
p.join()
|
||||
|
||||
print iterations, 'objects passed through the queue in', elapsed, 'seconds'
|
||||
print 'average number/sec:', iterations/elapsed
|
||||
print(iterations, 'objects passed through the queue in', elapsed, 'seconds')
|
||||
print('average number/sec:', iterations/elapsed)
|
||||
|
||||
|
||||
#### TEST_PIPESPEED
|
||||
|
|
@ -60,7 +60,7 @@ def pipe_func(c, cond, iterations):
|
|||
cond.notify()
|
||||
cond.release()
|
||||
|
||||
for i in xrange(iterations):
|
||||
for i in range(iterations):
|
||||
c.send(a)
|
||||
|
||||
c.send('STOP')
|
||||
|
|
@ -90,8 +90,8 @@ def test_pipespeed():
|
|||
elapsed = _timer() - t
|
||||
p.join()
|
||||
|
||||
print iterations, 'objects passed through connection in',elapsed,'seconds'
|
||||
print 'average number/sec:', iterations/elapsed
|
||||
print(iterations, 'objects passed through connection in',elapsed,'seconds')
|
||||
print('average number/sec:', iterations/elapsed)
|
||||
|
||||
|
||||
#### TEST_SEQSPEED
|
||||
|
|
@ -105,13 +105,13 @@ def test_seqspeed(seq):
|
|||
|
||||
t = _timer()
|
||||
|
||||
for i in xrange(iterations):
|
||||
for i in range(iterations):
|
||||
a = seq[5]
|
||||
|
||||
elapsed = _timer()-t
|
||||
|
||||
print iterations, 'iterations in', elapsed, 'seconds'
|
||||
print 'average number/sec:', iterations/elapsed
|
||||
print(iterations, 'iterations in', elapsed, 'seconds')
|
||||
print('average number/sec:', iterations/elapsed)
|
||||
|
||||
|
||||
#### TEST_LOCK
|
||||
|
|
@ -125,14 +125,14 @@ def test_lockspeed(l):
|
|||
|
||||
t = _timer()
|
||||
|
||||
for i in xrange(iterations):
|
||||
for i in range(iterations):
|
||||
l.acquire()
|
||||
l.release()
|
||||
|
||||
elapsed = _timer()-t
|
||||
|
||||
print iterations, 'iterations in', elapsed, 'seconds'
|
||||
print 'average number/sec:', iterations/elapsed
|
||||
print(iterations, 'iterations in', elapsed, 'seconds')
|
||||
print('average number/sec:', iterations/elapsed)
|
||||
|
||||
|
||||
#### TEST_CONDITION
|
||||
|
|
@ -141,7 +141,7 @@ def conditionspeed_func(c, N):
|
|||
c.acquire()
|
||||
c.notify()
|
||||
|
||||
for i in xrange(N):
|
||||
for i in range(N):
|
||||
c.wait()
|
||||
c.notify()
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ def test_conditionspeed(Process, c):
|
|||
|
||||
t = _timer()
|
||||
|
||||
for i in xrange(iterations):
|
||||
for i in range(iterations):
|
||||
c.notify()
|
||||
c.wait()
|
||||
|
||||
|
|
@ -171,8 +171,8 @@ def test_conditionspeed(Process, c):
|
|||
c.release()
|
||||
p.join()
|
||||
|
||||
print iterations * 2, 'waits in', elapsed, 'seconds'
|
||||
print 'average number/sec:', iterations * 2 / elapsed
|
||||
print(iterations * 2, 'waits in', elapsed, 'seconds')
|
||||
print('average number/sec:', iterations * 2 / elapsed)
|
||||
|
||||
####
|
||||
|
||||
|
|
@ -181,51 +181,51 @@ def test():
|
|||
|
||||
gc.disable()
|
||||
|
||||
print '\n\t######## testing Queue.Queue\n'
|
||||
test_queuespeed(threading.Thread, Queue.Queue(),
|
||||
print('\n\t######## testing Queue.Queue\n')
|
||||
test_queuespeed(threading.Thread, queue.Queue(),
|
||||
threading.Condition())
|
||||
print '\n\t######## testing multiprocessing.Queue\n'
|
||||
print('\n\t######## testing multiprocessing.Queue\n')
|
||||
test_queuespeed(multiprocessing.Process, multiprocessing.Queue(),
|
||||
multiprocessing.Condition())
|
||||
print '\n\t######## testing Queue managed by server process\n'
|
||||
print('\n\t######## testing Queue managed by server process\n')
|
||||
test_queuespeed(multiprocessing.Process, manager.Queue(),
|
||||
manager.Condition())
|
||||
print '\n\t######## testing multiprocessing.Pipe\n'
|
||||
print('\n\t######## testing multiprocessing.Pipe\n')
|
||||
test_pipespeed()
|
||||
|
||||
print
|
||||
print()
|
||||
|
||||
print '\n\t######## testing list\n'
|
||||
test_seqspeed(range(10))
|
||||
print '\n\t######## testing list managed by server process\n'
|
||||
test_seqspeed(manager.list(range(10)))
|
||||
print '\n\t######## testing Array("i", ..., lock=False)\n'
|
||||
test_seqspeed(multiprocessing.Array('i', range(10), lock=False))
|
||||
print '\n\t######## testing Array("i", ..., lock=True)\n'
|
||||
test_seqspeed(multiprocessing.Array('i', range(10), lock=True))
|
||||
print('\n\t######## testing list\n')
|
||||
test_seqspeed(list(range(10)))
|
||||
print('\n\t######## testing list managed by server process\n')
|
||||
test_seqspeed(manager.list(list(range(10))))
|
||||
print('\n\t######## testing Array("i", ..., lock=False)\n')
|
||||
test_seqspeed(multiprocessing.Array('i', list(range(10)), lock=False))
|
||||
print('\n\t######## testing Array("i", ..., lock=True)\n')
|
||||
test_seqspeed(multiprocessing.Array('i', list(range(10)), lock=True))
|
||||
|
||||
print
|
||||
print()
|
||||
|
||||
print '\n\t######## testing threading.Lock\n'
|
||||
print('\n\t######## testing threading.Lock\n')
|
||||
test_lockspeed(threading.Lock())
|
||||
print '\n\t######## testing threading.RLock\n'
|
||||
print('\n\t######## testing threading.RLock\n')
|
||||
test_lockspeed(threading.RLock())
|
||||
print '\n\t######## testing multiprocessing.Lock\n'
|
||||
print('\n\t######## testing multiprocessing.Lock\n')
|
||||
test_lockspeed(multiprocessing.Lock())
|
||||
print '\n\t######## testing multiprocessing.RLock\n'
|
||||
print('\n\t######## testing multiprocessing.RLock\n')
|
||||
test_lockspeed(multiprocessing.RLock())
|
||||
print '\n\t######## testing lock managed by server process\n'
|
||||
print('\n\t######## testing lock managed by server process\n')
|
||||
test_lockspeed(manager.Lock())
|
||||
print '\n\t######## testing rlock managed by server process\n'
|
||||
print('\n\t######## testing rlock managed by server process\n')
|
||||
test_lockspeed(manager.RLock())
|
||||
|
||||
print
|
||||
print()
|
||||
|
||||
print '\n\t######## testing threading.Condition\n'
|
||||
print('\n\t######## testing threading.Condition\n')
|
||||
test_conditionspeed(threading.Thread, threading.Condition())
|
||||
print '\n\t######## testing multiprocessing.Condition\n'
|
||||
print('\n\t######## testing multiprocessing.Condition\n')
|
||||
test_conditionspeed(multiprocessing.Process, multiprocessing.Condition())
|
||||
print '\n\t######## testing condition managed by a server process\n'
|
||||
print('\n\t######## testing condition managed by a server process\n')
|
||||
test_conditionspeed(multiprocessing.Process, manager.Condition())
|
||||
|
||||
gc.enable()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue