[Tutor] Psyco (Joseph Quigley)

Andrei project5 at redrival.net
Thu May 5 01:43:52 CEST 2005


Max Noel wrote on Wed, 4 May 2005 17:30:48 +0100:

> On May 4, 2005, at 16:35, Joseph Quigley wrote:
>> For those who use Psyco:
>>     Is it any good? I'm searching for instructions on how to use  
>> it, should I
>> stop?

Depends on the application. If you have a performance problem in the code
(this is an important aspect: don't waste your time on optimizing if there
is no problem), profile it to identify the source and try psyco-ing it. It
might help, but it might also not help. It's hard to predict its effects
without profiling beforehand, the speed increase factor may be anywhere
from say 100x (in extremely lucky situations) to 0, with code of average
optimizability probably being in the 2-5 range.

Note that in some cases algorithm improvements can give tremendous speed
boosts without any external help (e.g. I've seen in several cases factor 20
speed gains just by swithing from 'normal' algorithms to fancier features
in Python, using the built-in libraries wisely or implementation of simple
caching systems).

>      I hear it's quite good at what it does. Note, however, that it  
> only works on x86 computers (i.e. IBM PC compatibles).
>      Also, if speed is what your program needs, you should go all the  
> way and rewrite the critical parts in pure C. It's not very difficult  
> to do -- the tutorial on www.python.org explains how to do it.

I disagree there. Psyco can deliver significant speed improvements on
certain types of code at virtually no cost (something along the lines of 2
lines of Python code) and to make things even better, your code will still
run on computers without Psyco (only slower). That could be worth doing
even if you only shave a couple of seconds off something that runs
repeatedly. Coding in C might give better speed improvements, but at a
significantly larger investment of time *and* your code won't work unless
your custom module is present on the target machine.

>> For those who don't know about Psyco:
>>     It is supposed to be a Python Compiler. The programs are said  
>> to run
>> faster than normal Python and they almost run as fast as C.
> 
>      It's not a compiler. It's a JIT (Just-In-Time) compiler, a  
> little bit like HotSpot for Java.
>      Also, while it is faster than regular Python, it is still much  
> slower than C.

Except in some amusing cases:
http://mail.python.org/pipermail/python-list/2004-April/215272.html

-- 
Yours,

Andrei

=====
Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.



More information about the Tutor mailing list