[Numpy-discussion] Speed degression?
Travis Oliphant
oliphant.travis at ieee.org
Thu Jul 6 06:30:52 CDT 2006
Steffen Loeck wrote:
> Hi all,
>
> i made some speed tests using the sin-function and the %-operation to compare
> Numeric, numpy 0.9.8 and numpy 0.9.9.2732.
> As result the latest numpy version seems to be very slow in comparison to the
> two other candidates.
>
> Results (in usec per loop):
> sin-array mod-array
>
> Numeric 134 18
>
> numpy 0.9.8 97 55
>
> numpy 0.9.9.2732 204 316
>
> numpy 0.9.8 + math 38
>
> numpy 0.9.9.2732 + math 161
>
> Numeric + math 23
>
>
> The used scripts can be found at the end.
>
> Can anyone verify my results and explain the observed speed degression?
>
I can't verify the results, but it's possible that the indexing code for
a single integer is a bit slower.
However, you forgot to test the "use Python lists" approach which is the
fastest of all on this code.
python -m timeit -s "x = [0.1]*10;" "for i in xrange(9):
x[i+1]=(x[i]+1.1)%(1.0)"
Using Numeric/NumPy is always slower than lists if you are doing
element-by-element processing. NumPy is slower than Numeric for such
processing. But, Numeric was always slower than pure Python too for
such processing. So, the moral of the story is:
"don't compute like that with NumPy (or Numeric)"
With that said. I can add back the 1-d integer check in the indexing
code to see if that speeds things up...
-Travis
More information about the Numpy-discussion
mailing list