EDIT 2012-08-08: Added benchmarks in Firefox in addition to Chrome
Also, when trying to grok the discussion here and understanding the architectural challenges of matplotlib, it may be helpful to read the matplotlib chapter by John Hunter and yours truly from Architecture of Open Source Applications, Volume II.
The benchmarks compare a number of different possible approaches.
- Pure Python: This is just a simple pure Python implementation. transform.py
- Numpy: An implementation using vectorized Numpy operations. transform_numpy.py
- C extension: A hand-written C extension. transform.c
- Skulpt: Taking the pure Python implementation above, but running through Skulpt to get it to run inside of the browser.
- PyJs: Compiling the pure Python implementation above to Javascipt using PyJs, and then running the result in the browser.
The following results are on a quad-core Intel Core i5-2520M CPU @ 2.50GHz running Fedora Linux 17. Python 2.7.3, Numpy 1.6.1, Google Chrome 21.0.1180.57 beta and Firefox 14.0.1 were used. The benchmark is performing a 2D affine transformation on 128,000 points. Note that the timings in the web browser are quite variable. I've included the average and independent results of 5 runs.
So what can we conclude? Remember what I said about not reading too much into these results? Well, I'm going to do it anyway with an enormous caveat.
X = a*x + c*y + e
X = $p['__op_add']($add3=$p['__op_add']($add1=(typeof ($mul1=a)==typeof ($mul2=x) && typeof $mul1=='number'? $mul1*$mul2: $p['op_mul']($mul1,$mul2)),$add2=(typeof ($mul3=c)==typeof ($mul4=y) && typeof $mul3=='number'? $mul3*$mul4: $p['op_mul']($mul3,$mul4))),$add4=e);
Numpy and C extensions, of course, beat everything handily for this very numerically-biased benchmark.
Where does that leave us? Who knows... Interesting ride, though. Stay tuned and leave comments... There's more to hack away at.