multiprocessing pystone benchmark

A simple pystone benchmark using the python multiprocessing package. Seems to scale quite well - guess how many cores my machine has! 🙂


" Simple multiprocessing test.pystones benchmark "
" Anders Wallin 2008Jun15 anders.e.e.wallin (at) gmail.com "
from test import pystone
import processing
import time

STONES_PER_PROCESS= 10*pystone.LOOPS

def f(q):
    t=pystone.pystones(STONES_PER_PROCESS)
    q.put(t,block=True)

if __name__ == '__main__':
    print 'multiprocessing test.pystones() benchmark'
    print 'You have '+str(processing.cpuCount()) + ' CPU(s)'
    print 'Processes\tPystones\tWall time\tpystones/s'

    results = processing.Queue()
    for N in range(1,processing.cpuCount()+3):
        p=[]
        q=processing.Queue()
        results=[]

        for m in range(1,N+1):
            p.append( processing.Process(target=f,args=(q,)) )

        start=time.time()
        for pr in p:
            pr.start()
        for r in p:
            results.append( q.get() )
        stop=time.time()

        cputime = stop-start

        print str(N)+'\t\t'+str(N*STONES_PER_PROCESS) \
              +'\t\t'+ str(cputime)+'\t'+str( N*STONES_PER_PROCESS / cputime )

5 thoughts on “multiprocessing pystone benchmark”

  1. get rid of the backquotes `` and use if __name__ = '__main' if you'd like others to be able to run this without errors and post their results.

  2. '''Here is a slightly improved version that actually runs

    Simple multiprocessing pystone.pystones() benchmark '''
    ''' Anders Wallin 2008Jun15 anders.e.e.wallin (at) gmail.com '''
    from test import pystone
    import processing
    import time

    STONES_PER_PROCESS= 10*pystone.LOOPS

    def f(q):
    t=pystone.pystones(STONES_PER_PROCESS)
    q.put(t,block=True)

    if __name__ == '__main__':
    processing.freezeSupport()

    print 'multiprocessing test.pystones() benchmarkn'
    print 'You have '+str(processing.cpuCount()) + ' CPU(s)n'
    print 'ProcessestPystonestWall timetpystones/stSpeedup'

    results=processing.Queue()
    for N in range(1,processing.cpuCount()+3):
    p=[]
    q=processing.Queue()
    results=[]

    for m in range(1,N+1):
    p.append( processing.Process(target=f,args=(q,)) )

    start=time.time()
    for pr in p:
    pr.start()
    for r in p:
    results.append( q.get() )
    stop=time.time()

    cputime = stop-start
    if N==1: singlecpurate = N*STONES_PER_PROCESS / cputime

    print "%utt%utt%.1ftt%.ftt%.1fX" % (N, N*STONES_PER_PROCESS,
    cputime, N*STONES_PER_PROCESS / cputime,
    N*STONES_PER_PROCESS / (cputime * singlecpurate) )

  3. Thanks for the update, I spent some time changing it myself too. But my indentation got screwed up.
    You wanted 8 cores, here it is 🙂

    Xeon DP 2.66ghzx2 (E5430) = 8 cores total

    multiprocessing test.pystones() benchmark

    You have 8 CPU(s)

    Processes Pystones Wall time pystones/s Speedup
    1 500000 6.9 72727 1.0X
    2 1000000 6.8 147449 2.0X
    3 1500000 6.8 221729 3.0X
    4 2000000 6.8 292912 4.0X
    5 2500000 6.8 365283 5.0X
    6 3000000 6.8 438340 6.0X
    7 3500000 6.9 506806 7.0X
    8 4000000 6.9 577868 7.9X
    9 4500000 10.2 441739 6.1X
    10 5000000 11.3 441384 6.1X

  4. There is something going on with the quotes... I get a 'non ASCII-character' error with your program, but it runs OK if I change all the single-quotes to double-quotes.
    Perhaps you're on a unicode-only system?

    Thanks for the results, I've added them to the graph.

    As a further exercise I'm thinking of comparing pystones or another benchmark using different speedup techniques, i.e. psyco, cython etc,
    shedskin looks very interesting: http://code.google.com/p/shedskin/

Comments are closed.