summaryrefslogtreecommitdiffstats
path: root/Doc/includes/mp_benchmarks.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-11-28 11:23:26 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-11-28 11:23:26 (GMT)
commitaae1b70a83094314043ad65fc098b2aa7137c294 (patch)
treea78a27e7d4a5090810b337ee2ff6160c98a91c23 /Doc/includes/mp_benchmarks.py
parent94e0772989073d207855a787a59f863f79230771 (diff)
downloadcpython-aae1b70a83094314043ad65fc098b2aa7137c294.zip
cpython-aae1b70a83094314043ad65fc098b2aa7137c294.tar.gz
cpython-aae1b70a83094314043ad65fc098b2aa7137c294.tar.bz2
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 ...
Diffstat (limited to 'Doc/includes/mp_benchmarks.py')
-rw-r--r--Doc/includes/mp_benchmarks.py84
1 files changed, 42 insertions, 42 deletions
diff --git a/Doc/includes/mp_benchmarks.py b/Doc/includes/mp_benchmarks.py
index 425d6de..4556de0 100644
--- a/Doc/includes/mp_benchmarks.py
+++ b/Doc/includes/mp_benchmarks.py
@@ -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()