psyco, jython, and python speed tests

Sandy Norton sandskyfly at hotmail.com
Sat Mar 16 05:17:59 EST 2002


> Skip> How did you "psycoize pystone"?
> 
>     Sandy> Basically, I took the pystone included in Armin's psyco cvs
>     Sandy> distribution and simplified the main() function to get rid of the
>     Sandy> comparitive stuff.
> 
> Modification of the source to pystone is a no-no, otherwise you're comparing
> apples and oranges.  Instead, try something like
> 
>     >>> import pystone
>     >>> pystone.main()
>     Pystone(1.1) time for 10000 passes = 2.51
>     This machine benchmarks at 3984.06 pystones/second
>     >>> pystone.main()
>     Pystone(1.1) time for 10000 passes = 2.54
>     This machine benchmarks at 3937.01 pystones/second
>     >>> pystone.main()
>     Pystone(1.1) time for 10000 passes = 2.53
>     This machine benchmarks at 3952.57 pystones/second
>     >>> import psyco
>     >>> pystone.Proc0 = psyco.proxy(pystone.Proc0)
>     >>> pystone.Proc1 = psyco.proxy(pystone.Proc1)
>     >>> pystone.Proc8 = psyco.proxy(pystone.Proc8)
>     >>> pystone.main()
>     Pystone(1.1) time for 10000 passes = 0.58
>     This machine benchmarks at 17241.4 pystones/second
>     >>> pystone.main()
>     Pystone(1.1) time for 10000 passes = 0.57
>     This machine benchmarks at 17543.9 pystones/second
>     >>> pystone.main()
>     Pystone(1.1) time for 10000 passes = 0.58
>     This machine benchmarks at 17241.4 pystones/second

I agree that your method is cleaner. My modification, however, was
actually an attempt to bring the version of pystone included in psyco
cvs closer to the one in the standard python distro, all while
retaining Armin's explicit use of psyco.proxy()

Just for comparison here are the main functions of each version of
psyco:

Standard pystone (py22 distro)
------------------------------
def main():
    benchtime, stones = pystones()
    print "Pystone(%s) time for %d passes = %g" % \
          (__version__, LOOPS, benchtime)
    print "This machine benchmarks at %g pystones/second" % stones


My modified psyco pystone (psyco cvs distro)
----------------------------------------------
def main():
    print "Pystone(%s) time loops per second" % __version__
    psy_time = pystones_psycho(LOOPS)[0]
    print "Psyco for %d passes %g %g" % (LOOPS, psy_time, mydiv(LOOPS,
psy_time))


Unmodified psyco psytone (psyco cvs distro)
-------------------------------------------
def main():
    print "Pystone(%s)                   time     loops per second" %
__version__
    py_time, = pystones_reg(LOOPS1+LOOPS)
    pyloop_time = py_time / (LOOPS1+LOOPS)
    print "regular Python for %d passes  %g        %g" % \
          (LOOPS1+LOOPS, py_time, mydiv(1, pyloop_time))
    psy_time1, psy_time = pystones_psycho(LOOPS1, LOOPS)
    print "Psyco for %d passes           %g        %g" % \
          (LOOPS1, psy_time1, mydiv(LOOPS1, psy_time1))
    print "Psyco for %d more passes      %g        %g" % \
          (LOOPS, psy_time, mydiv(LOOPS, psy_time))
    print "Total for %d passes           %g        %g" % \
          (LOOPS1+LOOPS, psy_time1+psy_time, 
             mydiv(LOOPS1+LOOPS, psy_time1+psy_time))

    # invert the equation system:
    #   psy_time1          = start_time + LOOPS1*loop_time
    #   psy_time1+psy_time = start_time + (LOOPS1+LOOPS)*loop_time
    loop_time = psy_time/LOOPS
    start_time = psy_time1 - LOOPS1*loop_time
    print "Separated compilation/execution timings for %d passes" % \
          (LOOPS1+LOOPS)
    print "Compilation (i.e. start-up)   %g        %g" % \
          (start_time, mydiv(1, start_time))
    print "Machine code execution        %g        %g" % \
          (loop_time*(LOOPS1+LOOPS), mydiv(1, loop_time))
    print
    print "Relative execution frequencies (iterations per second)"
    print "iterations        Psyco        Python    Psyco is ... times
faster"
    for d in range(8):
        n = 10**d
        psyco1 = mydiv(n, start_time+n*loop_time)
        print " %8d       %g         %g           %.2f" % \
            (n, psyco1, mydiv(1, pyloop_time), psyco1*pyloop_time)

    # invert the equation
    #   start_time + c*loop_time = c*pyloop_time
    if pyloop_time <= loop_time:
        print "Psyco is always slower than regular Python."
    else:
        c = mydiv(start_time, pyloop_time - loop_time)
        print "Cut-off point: %.1f iterations" % c
    if start_time < 0.07:
        print "Note: start-up time is very low, the above figure is
not reliable."
        print "You should consider running the same benchmark a large
number of times"
        print "and taking the mean value for the cut-off point."

--------

What's important in any case is that Psyco most definitely accelerates
your code. I've actually tried it in a practical example using certain
calculations with sparse matrices and it more than halved my execution
time.

regards,

Sandy



More information about the Python-list mailing list