Psyco performance

danmcleran at yahoo.com danmcleran at yahoo.com
Wed Jun 21 10:07:48 EDT 2006


> > > Place all the code in a function. Even without psyco you might get
> > > somewhat better performances then. And I doubt psyco can optimise code
> > > that isn't in a function anyway.

Another thing I wasn't considering is that the first call with psyco
enabled might be slower. The 2nd time the psyco-compiled function is
called is where the speed improvement may be present. With the code at
the bottom, I get these results:

without psyco =  0.000421282593179
first call with psyco =  0.000902349320933
with psyco =  5.30793718196e-005
first call with psyco =  114.190981432 %  slower
2nd call with psyco =  87.400530504 %  faster


import time
import psyco

def test(l):
    result = 0

    for item in l:
        result += item

    return result

l = list(range(0, 1000))

t1 = time.clock()
l2 = test(l)
t2 = time.clock()
no_psyco = t2 - t1

psyco.log()
psyco.bind(test)

t1 = time.clock()
l2 = test(l)
t2 = time.clock()

first_call_with_psyco = t2 - t1

t1 = time.clock()
l2 = test(l)
t2 = time.clock()

with_psyco = t2 - t1

print 'without psyco = ',no_psyco
print 'first call with psyco = ',first_call_with_psyco
print 'with psyco = ',with_psyco
first_delta = ((no_psyco - first_call_with_psyco)/no_psyco) * 100
delta = ((no_psyco - with_psyco)/no_psyco) * 100

if(first_delta > 0):
    result = 'faster'
else:
    result = 'slower'

print 'first call with psyco = ',abs(first_delta),'% ',result

if(delta > 0):
    result = 'faster'
else:
    result = 'slower'
    
print '2nd call with psyco = ',abs(delta),'% ',result




More information about the Python-list mailing list