Site menu Which performance can you expect from Python and Javascript?
e-mail icon
Site menu

Which performance can you expect from Python and Javascript?

e-mail icon

This is not a comprehensive benchmark; it is a wrap-up of performance tests made on a stock options trading simulator, which I wrote to test some trading hypothesis for my book.

The simulation is CPU-bound and depends mostly on math performance. It was initially written in Python, but was unbearably slow. I optimized it to the point that it was o.k., and ran the tests I wanted.

Afterwards, I converted one particular simulation to Javascript, Ruby and C in order to compare the performance.

First versionaround 4:40
Some duplicated calculations elided2:17
Optimized with Psyco (psyco.full()) 0:23
Black-Scholes functions converted to Cython, with static typing, and without Psyco0:40
Psyco + Cython initial optimization0:10
random.gauss(), highlited by profiling, converted to Cython0:07
Some max() calls in Cython code replaced by a Cython local function, plus a power of 0.5 replaced by sqrt()0:06
Cython cdivision flag set to True0:05.7
Cython-written module compiled with -O90:05.4
Clean-up in stop-loss function, avoid if..elif chain for several strategies0:05.1
Simplified calculation, returns only total value instead of every option's value (which was only necessary when logging/debugging)0:04.8
Avoid value recalculation on stop loss when possible0:04:4
Whole simulation converted to C0:02.1
C version compiled with -O90:01.5 (*)
Save a call to gauss() when there is no volatility skew0:01:3
Same simulation converted to Javascriptaround 0:08
Same simulation converted to Rubyslower than Python
Same simulation converted to PHParound 1:30

(*) Guess what, it does make a difference!

The conclusions I drew from these numbers and some other things that I observed during the tests:

e-mail icon