[Numpy-discussion] Performance problems with strided arrays in NumPy

Travis Oliphant oliphant at ee.byu.edu
Tue Apr 18 20:03:01 CDT 2006


faltet at xot.carabos.com wrote:

>Hi,
>
>I'm seeing some slowness in NumPy when dealing with strided arrays.
>numarray is dealing better with these situations, so I guess that
>something could be done in NumPy about this. Below are the situations
>that I've found up to now (maybe there are others). For the timings,
>I've used numpy 0.9.7.2278 and numarray 1.5.1.
>  
>
The source of this slowness is the use in numarray of  special-cases for 
certain-sized byte-copies.

Apparently,  it is *much* faster to do

((double *)dst)[0] = ((double *)src)[0]

when you have aligned data than it is to do

memmove(dst, src, sizeof(double))

This is a useful piece of knowledge to have for optimization.  There may 
be other optimizations like that already used by Numarray but still 
needing to be adapted for NumPy.

I applied an optimization to take advantage of this when possible and 
got a 10x speed-up in the 1-d case.

My timings for your benchmark with current SVN of NumPy are:

NumPy: [0.021701812744140625, 0.021739959716796875, 0.021548032760620117]
Numarray: [0.052516937255859375, 0.052685976028442383, 0.052355051040649414]


Old timings:

NumPy: [~0.09, ~0.09, ~0.09]
Numarray: [~0.05, ~0.05, ~0.05]


-Travis






More information about the Numpy-discussion mailing list