EPx professional blog and repository for braindumps

2010/03/07

Small test with Unladen Swallow

I have been working on a new book about stock options, this time with a "dirty hands" approach. As part of the effort, I have been developing a strategy simulation tool in Python language. Given some market and simulation parameters, the application "does" 100 thousand "operations" and spits out average return and volatility:


The above output is just one scenario. Thousands of scenarios must be analyzed. For easier examination of the data mass, it is plotted as a graph by a Python/TkInter script:


Each simulation scenario becomes just six points in the above graph (one for each color). It takes a lot of processing time to simulate all of this, especially because each operation must be simulated in a day-by-day basis, in order to test strategy against "gaps" and "stops" and all this investment stuff.

Soon it was clear that the task would take weeks with standard Python. Then I remembered about Psyco, the Python JIT compiler. Using Psyco gave an immediate 4x performance boost:


Compounding this with concurrent simulation of two scenarios (putting both CPUs into use), simulation time became a matter of days, not weeks. The most attractive trait of Psyco is simplicity of usage -- just two lines of code at the beginning of script:



In the last few weeks, we have heard a lot about Unladen Swallow, Google's approach to add JIT into standard Python interpreter (with great chance of integration into vanilla Python). I have compiled the trunk version, and it worked normally with my script:


Gain was around 1.6x, less than Psyco, but still noteworthy. Note that Psyco is i386-only, while Unladen works for every architecture supported by LLVM. The above Unladen exacutable is truly 64-bit, while Snow Leopard's Python must be configured to run in 32-bit in order to accomodate Psyco.

I could not compila 32-bit version of Unladen (not even an Universal one, which I could lipo 64-bit out). That would allow for a more fair comparison with Psyco. Still, I feel Unladen already provides palpable performance gains and it is in the right path. It is good to see a Python optimization project to go forward. Even better if they manage to remove GIL.

1 comentários:

Luis disse...

By the end of March, you'll be able to test pypy's jit (1.2 version release). It already yields some impressive results in several benchmarks: http://speed.pypy.org/overview

Luis

Postar um comentário