Back to index

python3.2  3.2.2
Functions | Variables
mp_benchmarks Namespace Reference

Functions

def queuespeed_func
 TEST_QUEUESPEED.
def test_queuespeed
def pipe_func
 TEST_PIPESPEED.
def test_pipespeed
def test_seqspeed
 TEST_SEQSPEED.
def test_lockspeed
 TEST_LOCK.
def conditionspeed_func
 TEST_CONDITION.
def test_conditionspeed
def test

Variables

 _timer = time.clock
int delta = 1

Function Documentation

def mp_benchmarks.conditionspeed_func (   c,
  N 
)

TEST_CONDITION.

Definition at line 148 of file mp_benchmarks.py.

00148 
00149 def conditionspeed_func(c, N):
00150     c.acquire()
00151     c.notify()
00152 
00153     for i in range(N):
00154         c.wait()
00155         c.notify()
00156 
00157     c.release()

def mp_benchmarks.pipe_func (   c,
  cond,
  iterations 
)

TEST_PIPESPEED.

Definition at line 65 of file mp_benchmarks.py.

00065 
00066 def pipe_func(c, cond, iterations):
00067     a = '0' * 256
00068     cond.acquire()
00069     cond.notify()
00070     cond.release()
00071 
00072     for i in range(iterations):
00073         c.send(a)
00074 
00075     c.send('STOP')

def mp_benchmarks.queuespeed_func (   q,
  c,
  iterations 
)

TEST_QUEUESPEED.

Definition at line 25 of file mp_benchmarks.py.

00025 
00026 def queuespeed_func(q, c, iterations):
00027     a = '0' * 256
00028     c.acquire()
00029     c.notify()
00030     c.release()
00031 
00032     for i in range(iterations):
00033         q.put(a)
00034 
00035     q.put('STOP')

Definition at line 187 of file mp_benchmarks.py.

00187 
00188 def test():
00189     manager = multiprocessing.Manager()
00190 
00191     gc.disable()
00192 
00193     print('\n\t######## testing Queue.Queue\n')
00194     test_queuespeed(threading.Thread, queue.Queue(),
00195                     threading.Condition())
00196     print('\n\t######## testing multiprocessing.Queue\n')
00197     test_queuespeed(multiprocessing.Process, multiprocessing.Queue(),
00198                     multiprocessing.Condition())
00199     print('\n\t######## testing Queue managed by server process\n')
00200     test_queuespeed(multiprocessing.Process, manager.Queue(),
00201                     manager.Condition())
00202     print('\n\t######## testing multiprocessing.Pipe\n')
00203     test_pipespeed()
00204 
00205     print()
00206 
00207     print('\n\t######## testing list\n')
00208     test_seqspeed(list(range(10)))
00209     print('\n\t######## testing list managed by server process\n')
00210     test_seqspeed(manager.list(list(range(10))))
00211     print('\n\t######## testing Array("i", ..., lock=False)\n')
00212     test_seqspeed(multiprocessing.Array('i', list(range(10)), lock=False))
00213     print('\n\t######## testing Array("i", ..., lock=True)\n')
00214     test_seqspeed(multiprocessing.Array('i', list(range(10)), lock=True))
00215 
00216     print()
00217 
00218     print('\n\t######## testing threading.Lock\n')
00219     test_lockspeed(threading.Lock())
00220     print('\n\t######## testing threading.RLock\n')
00221     test_lockspeed(threading.RLock())
00222     print('\n\t######## testing multiprocessing.Lock\n')
00223     test_lockspeed(multiprocessing.Lock())
00224     print('\n\t######## testing multiprocessing.RLock\n')
00225     test_lockspeed(multiprocessing.RLock())
00226     print('\n\t######## testing lock managed by server process\n')
00227     test_lockspeed(manager.Lock())
00228     print('\n\t######## testing rlock managed by server process\n')
00229     test_lockspeed(manager.RLock())
00230 
00231     print()
00232 
00233     print('\n\t######## testing threading.Condition\n')
00234     test_conditionspeed(threading.Thread, threading.Condition())
00235     print('\n\t######## testing multiprocessing.Condition\n')
00236     test_conditionspeed(multiprocessing.Process, multiprocessing.Condition())
00237     print('\n\t######## testing condition managed by a server process\n')
00238     test_conditionspeed(multiprocessing.Process, manager.Condition())
00239 
00240     gc.enable()

Here is the call graph for this function:

def mp_benchmarks.test_conditionspeed (   Process,
  c 
)

Definition at line 158 of file mp_benchmarks.py.

00158 
00159 def test_conditionspeed(Process, c):
00160     elapsed = 0
00161     iterations = 1
00162 
00163     while elapsed < delta:
00164         iterations *= 2
00165 
00166         c.acquire()
00167         p = Process(target=conditionspeed_func, args=(c, iterations))
00168         p.start()
00169 
00170         c.wait()
00171 
00172         t = _timer()
00173 
00174         for i in range(iterations):
00175             c.notify()
00176             c.wait()
00177 
00178         elapsed = _timer() - t
00179 
00180         c.release()
00181         p.join()
00182 
00183     print(iterations * 2, 'waits in', elapsed, 'seconds')
00184     print('average number/sec:', iterations * 2 / elapsed)

Here is the caller graph for this function:

TEST_LOCK.

Definition at line 127 of file mp_benchmarks.py.

00127 
00128 def test_lockspeed(l):
00129     elapsed = 0
00130     iterations = 1
00131 
00132     while elapsed < delta:
00133         iterations *= 2
00134 
00135         t = _timer()
00136 
00137         for i in range(iterations):
00138             l.acquire()
00139             l.release()
00140 
00141         elapsed = _timer() - t
00142 
00143     print(iterations, 'iterations in', elapsed, 'seconds')
00144     print('average number/sec:', iterations/elapsed)
00145 

Here is the caller graph for this function:

Definition at line 76 of file mp_benchmarks.py.

00076 
00077 def test_pipespeed():
00078     c, d = multiprocessing.Pipe()
00079     cond = multiprocessing.Condition()
00080     elapsed = 0
00081     iterations = 1
00082 
00083     while elapsed < delta:
00084         iterations *= 2
00085 
00086         p = multiprocessing.Process(target=pipe_func,
00087                                     args=(d, cond, iterations))
00088         cond.acquire()
00089         p.start()
00090         cond.wait()
00091         cond.release()
00092 
00093         result = None
00094         t = _timer()
00095 
00096         while result != 'STOP':
00097             result = c.recv()
00098 
00099         elapsed = _timer() - t
00100         p.join()
00101 
00102     print(iterations, 'objects passed through connection in',elapsed,'seconds')
00103     print('average number/sec:', iterations/elapsed)
00104 

Here is the call graph for this function:

Here is the caller graph for this function:

def mp_benchmarks.test_queuespeed (   Process,
  q,
  c 
)

Definition at line 36 of file mp_benchmarks.py.

00036 
00037 def test_queuespeed(Process, q, c):
00038     elapsed = 0
00039     iterations = 1
00040 
00041     while elapsed < delta:
00042         iterations *= 2
00043 
00044         p = Process(target=queuespeed_func, args=(q, c, iterations))
00045         c.acquire()
00046         p.start()
00047         c.wait()
00048         c.release()
00049 
00050         result = None
00051         t = _timer()
00052 
00053         while result != 'STOP':
00054             result = q.get()
00055 
00056         elapsed = _timer() - t
00057 
00058         p.join()
00059 
00060     print(iterations, 'objects passed through the queue in', elapsed, 'seconds')
00061     print('average number/sec:', iterations/elapsed)
00062 

Here is the caller graph for this function:

TEST_SEQSPEED.

Definition at line 107 of file mp_benchmarks.py.

00107 
00108 def test_seqspeed(seq):
00109     elapsed = 0
00110     iterations = 1
00111 
00112     while elapsed < delta:
00113         iterations *= 2
00114 
00115         t = _timer()
00116 
00117         for i in range(iterations):
00118             a = seq[5]
00119 
00120         elapsed = _timer() - t
00121 
00122     print(iterations, 'iterations in', elapsed, 'seconds')
00123     print('average number/sec:', iterations/elapsed)
00124 

Here is the caller graph for this function:


Variable Documentation

mp_benchmarks._timer = time.clock

Definition at line 16 of file mp_benchmarks.py.

Definition at line 20 of file mp_benchmarks.py.