2010/03/12

Small test with PyPy 1.2

Ok, just some days after the Unladen Swallow experiment, PyPy 1.2 JIT was out. I used the Mac OS X binary offered by PyPy site.

The results were good. Using exactly the same script with the same parameters (that one that simulates stock option operations), PyPy delivers a 3.1x performance gain, which is twice the Unladen's 1.6x, and almost as good as Psyco (3.6x, in my specific case).

The only strange thing that happened: I protected the psyco invocation by a try..except block, so the script wouldn't fail in case of Pysyco absence:


try:
import psyco
psyco.full()
except:
pass


Even though the psyco import fails under PyPy interpreter, the presence of this block causes very strange errors in certain math functions:


File "/Users/epx/agenda/novolivro/gen/blackscholes.py", line 24, in N
return 1 - N(-x)
File "/Users/epx/agenda/novolivro/gen/blackscholes.py", line 24, in N
return 1 - N(-x)
RuntimeError: internal error (stack overflow?)


or, sometimes,


OverflowError: math range error


and sometimes the very same script runs just fine.

Actually, Psyco does not need to be involved; any try..except block which raises exceptions will exercise the error (a simple "print unknown_var" will do). In the other hand, removing the block (or not raising exceptions in it) avoids the problem entirely.
blog comments powered by Disqus