473,473 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Psyco performance

I'm not seeing much benefit from psyco (only 5-10% faster). Maybe this
example is too trivial? Can someone give me some pointers as to what
kind of code would see a dramatic benefit?

Here's the code:

import time
import psyco

n = 100000

t1 = time.clock()
l = list(range(0,n))
l2 = [x**2 for x in l]
t2 = time.clock()
no_psyco = t2 - t1

psyco.log()
psyco.full()

t1 = time.clock()
l = list(range(0,n))
l2 = [x**2 for x in l]
t2 = time.clock()

with_psyco = t2 - t1

print 'without psyco = ',no_psyco
print 'with psyco = ',with_psyco
print 'delta = ',(((no_psyco - with_psyco)/no_psyco) * 100),'%'

Jun 20 '06 #1
6 1591
da********@yahoo.com wrote:
I'm not seeing much benefit from psyco (only 5-10% faster). Maybe this
example is too trivial? Can someone give me some pointers as to what
kind of code would see a dramatic benefit?

Here's the code:

import time
import psyco

n = 100000

t1 = time.clock()
l = list(range(0,n))
l2 = [x**2 for x in l]
t2 = time.clock()
no_psyco = t2 - t1

psyco.log()
psyco.full()

t1 = time.clock()
l = list(range(0,n))
l2 = [x**2 for x in l]
t2 = time.clock()

with_psyco = t2 - t1

print 'without psyco = ',no_psyco
print 'with psyco = ',with_psyco
print 'delta = ',(((no_psyco - with_psyco)/no_psyco) * 100),'%'


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.
Jun 20 '06 #2
What's the reasoning behind requiring everything to be in functions?
Just curious.

On 6/20/06, Christophe <ch*************@free.fr> wrote:

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.

Jun 20 '06 #3
Hello,

Gregory Piñero a écrit :
What's the reasoning behind requiring everything to be in functions?
Just curious.


You may want to read this:

http://psyco.sourceforge.net/introdu...-jit-compilers

Psyco has to run the code at least once to emit code specialized for the
actual data. It works by replacing blocks of code by other blocks,
optimized for the kind of data seen the previous times.

On the contrary, the code outside functions is run only once. You'll
never get the chance to run the optimized version again...

--
Amaury
Jun 20 '06 #4
> 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

Jun 20 '06 #5
<da********@yahoo.com> wrote in message
news:11**********************@r2g2000cwb.googlegro ups.com...
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

Here are 3 different implementations of foo, with varying degrees of
improvement.

func without with
foo1: 0.1727 0.0106
foo2: 0.1020 0.1012
foo3: 0.3632 0.8068

foo1 is just a brute force for-loop summing the values of the composed list,
foo2 calls sum(), and foo3 is the original foo using reduce().
Surprisingly, brute force + psyco beats reduce and sum without psyco.

psyco's strength is in compiling Python code inside functions. In foo2 and
foo3, most of the processing is done not in explicit Python, but in C code
implementation of sum and reduce, so the psyco processing is actually adding
more than it is optimizing.

-- Paul
import time
import psyco
time.clock()

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

def foo1(self):
z = 0
for i in range(self.value):
z += i
return z

def foo2(self):
return sum(list(range(0,self.value)))

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

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

n = 1000
fns = (Test.foo1, Test.foo2, Test.foo3)
no_psyco = []
with_psyco = []

for fn in fns:
t1 = time.clock()
l2 = test(n,fn)
t2 = time.clock()
no_psyco.append( t2 - t1 )

psyco.full()

for fn in fns:
t1 = time.clock()
l2 = test(n,fn)
t2 = time.clock()
with_psyco.append( t2 - t1 )

for fnData in zip([f.func_name for f in fns],no_psyco,with_psyco):
print "%s: %.4f %.4f" % fnData
Jun 21 '06 #6
> > > 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

Jun 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: KefX | last post by:
Hey...as for what I'm doing with Python, look at my post "Strange Hotshot problem". To make a long story short, I'm embedding Python in order to write a plugin to a freeware music program; the...
10
by: William S. Perrin | last post by:
I'm a python rookie, anyone have and suggestions to streamline this function? Thanks in advance..... def getdata(myurl): sock = urllib.urlopen(myurl) xmlSrc = sock.read() sock.close() ...
0
by: Jeremy Sanders | last post by:
Hi - I'm trying to build a Psyco rpm on Fedora 1. I try the command xpc5:~/psyco-1.1.1> python setup.py bdist_rpm this fails with: .... copying dist/psyco-1.1.1.tar.gz ->...
7
by: Ivan Voras | last post by:
I have this simple *dumb* benchmark-like program: #import psyco #psyco.full() d = 0.0 for i in xrange(1000000000): d += i print d
3
by: Dick Moores | last post by:
psyco is acting a bit psycho for me. Please see my spinForWeb.py at <http://www.rcblue.com/Python/spinForWeb.py> When psyco is in use, entering an integer somewhere between 2000 and 2500...
5
by: Fausto Arinos Barbuto | last post by:
Hi All; I have Psyco (on Windows XP) and now I want to install it on Linux, too. I FTP'd the tarball (tar.gz) from Psyco's site but can't get it compiled. First, I tried the usual "python...
3
by: a | last post by:
hi i tried psyco+webpy here is the error that i got please let me know if any of you has success run psyco+webpy thanks import web, psyco urls = ( '/', 'view', '/add','add'
0
by: thattommyhallll | last post by:
i am doing the problems at http://www.mathschallenge.net/index.php?section=project one problem involved finding factors, i used def divisors(n): divisors = set() for i in range(1, math.ceil(n...
4
by: miller.paul.w | last post by:
Say I have a module with a function f in it, and I do psyco.bind (f) Is there any simple/easy/elegant way to retain a reference to the *unoptimized* version of f so I can call them both and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.