[Numpy-discussion] Interesting Psyco/Numeric/Numarray comparison

Tim Hochberg tim.hochberg at ieee.org
Tue Feb 4 08:52:05 CST 2003

```I was inspired by Armin's latest Psyco version to try and see how well
one could do with NumPy/NumArray implemented in Psycotic Python. I wrote
a bare bones, pure Python, Numeric array class loosely based on Jnumeric
(which in turn was loosely based on Numeric). The buffer is just
Python's array.array. At the moment, all that one can do to the arrays
is add and index them and the code is still a bit of a mess. I plan to
clean things up over the next week in my copius free time <0.999 wink>
and at that point it should be easy add the remaining operations.

I benchmarked this code, which I'm calling Psymeric for the moment,
against NumPy and Numarray to see how it did. I used a variety of array
sizes, but mostly relatively large arrays of shape (500,100) and of type
Float64 and Int32 (mixed and with consistent types) as well as scalar
values. Looking at the benchmark data one comes to three main conclusions:
* For small arrays NumPy always wins. Both Numarray and Psymeric have
* For large, contiguouse arrays, Numarray is about twice as fast as
either of the other two.
* For large, noncontiguous arrays, Psymeric and NumPy are ~20% faster
than Numarray
The impressive thing is that Psymeric is generally slightly faster than
NumPy when adding two arrays. It's slightly slower (~10%) when adding an
array and a scalar although I suspect that could be fixed by some
special casing a la Numarray. Adding two (500,100) arrays of type
Float64 together results in the following timings:
psymeric      numpy       numarray
contiguous  0.0034 s      0.0038 s    0.0019 s
stride-2      0.0020 s      0.0023 s    0.0033 s

I'm not sure if this is important, but it is an impressive demonstration
of Psyco! More later when I get the code a bit more cleaned up.

-tim
0.002355

0.002355

```