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.
|First version||around 4:40|
|Some duplicated calculations elided||2:17|
|Optimized with Psyco (psyco.full())||0:23|
|Black-Scholes functions converted to Cython, with static typing, and without Psyco||0:40|
|Psyco + Cython initial optimization||0:10|
|random.gauss(), highlited by profiling, converted to Cython||0: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 True||0:05.7|
|Cython-written module compiled with -O9||0:05.4|
|Clean-up in stop-loss function, avoid if..elif chain for several strategies||0: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 possible||0:04:4|
|Whole simulation converted to C||0:02.1|
|C version compiled with -O9||0:01.5 (*)|
|Save a call to gauss() when there is no volatility skew||0:01:3|
|Same simulation converted to Ruby||slower than Python|
|Same simulation converted to PHP||around 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: