Psyco performance

danmcleran at yahoo.com danmcleran at yahoo.com
Tue Jun 20 17:42:30 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.
>
> And lastly, most of the code is probably spend computing x**2 which is
> already optimised C code.

I've changed the code to include a class, method call, and function.
Now the Psyco code is quite a bit slower. Is this a valid way to test
Psyco's effects? When I run the following code I get this result:

without psyco =  0.96840101186
with psyco =  1.82430169197
with psyco =  0.855900680114 slower


The code:

import time
import psyco

class Test(object):
    def __init__(self, value):
        self.value = value

    def foo(self):
        return reduce(lambda x,y : x + y, list(range(0,self.value)))

def test(n):
    l = [Test(i) for i in range(1, n)]
    return [x.foo() for x in l]

n = 1000

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

psyco.full()

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

with_psyco = t2 - t1

print 'without psyco = ',no_psyco
print 'with psyco = ',with_psyco
delta = (no_psyco - with_psyco)
if(delta > 0):
    result = 'faster'
else:
    result = 'slower'
    
print 'with psyco = ',abs(delta),result




More information about the Python-list mailing list