arigo at ulb.ac.be
Sat Nov 10 20:45:00 CET 2001
Finally, the first usable version of Psyco. It compiles small but
realistic code examples.
The included text files can also be read at
Not all Python bytecodes are implemented, but you can already do quite a
lot. The missing ones are the ones that cannot be really optimized any
more, so they should be easy to implement as a call to a run-time
I used Python 2.2b1's new typing system to figure out when an attribute is
a method. It should still compile with older Python version but you will
not get method access optimization.
There are a few cases in which Psyco does not exactly follow Python's
semantics, mainly with globals/builtins. Builtins are assumed never to
change, and we assume that the user will not later add or remove a global
variable that will shadow or expose a builtin. This issue and others are
discussed in detail in ISSUES.txt.
Produced code buffers are never freed. This is a problem for larger
examples. See ISSUES.txt. This file will also give you cool examples of
Python code which are known tricks to speed up the interpreter but which
are no longer needed -- Psyco is able to optimize them correctly. One such
nice example is 'range', which is now actually faster than 'xrange', and
completely transparent (for x in sequence is equivalent to for i in
range(len(sequence)): x = sequence[i]).
Inspecting the produced machine code is now possible if you have GDB (the
GNU debugger) installed. There is a script that presents the produced
cross-calling code buffers as cross-linked HTML pages.
And finally... (drums...) some timing results. This is for my notebook
Intel PIII 700Mhz with all optimization turned on.
Note however that none of these small examples is typical of Python code;
they are all small compact algorithms not using complex data structures.
f1() is designed specifically for the purpose of showing how fast Psyco is
;-) It works on integers only, and is not at all a real-world algorithm.
f2() and f3() are too trivial to be timed. f4() is a function that loads
a list of files and counts the number of times each character appears. Ok,
this is also a case in which Psyco will clearly win. f5() is like f4()
but completely loads the files in memory, whereas f4() loads them line by
line. f6() computes the factorial modulo p, using long integers, whose
operations are not optimized by Psyco. f7() is the Mandelbrot set.
Float/complex not optimized by Psyco. In the latter two examples the gain
is only on the stuff around the actual computations.
The table is in seconds, as returned by time.clock(), so the numbers don't
include delays for loading the (relatively large) code of Psyco itself nor
Psyco, first call Psyco, next calls Python -OO
go1() 0.03 0.02 to 0.03 3.63
go4() 0.35 0.33 3.59
go5() 0.29 0.27 3.47
go6() 0.87 0.85 1.03 to 1.07
go7() 2.16 to 2.18 2.16 to 2.18 2.83
Interesting, isn't it ?
More information about the Python-list