[Numpy-discussion] numpy 10x slower than native Python arrays for simple operations?

Charles R Harris charlesr.harris at gmail.com
Sat Feb 6 16:50:34 EST 2010


On Sat, Feb 6, 2010 at 2:21 PM, Joseph Turian <turian at gmail.com> wrote:

> I have done some profiling, and the results are completely
> counterintuitive. For simple array access operations, numpy and
> array.array are 10x slower than native Python arrays.
>
> I am using numpy 1.3.0, the standard Ubuntu 9.03 package.
>
> Why am I getting such slow access speeds?
> Note that for "array access", I am doing operations of the form:
>    a[i] += 1
>
> Profiles:
>
> [0] * 20000000
>   Access: 2.3M / sec
>   Initialization: 0.8s
>
> numpy.zeros(shape=(20000000,), dtype=numpy.int32)
>   Access: 160K/sec
>   Initialization: 0.2s
>
> array.array('L', [0] * 20000000)
>   Access: 175K/sec
>   Initialization: 2.0s
>
> array.array('L', (0 for i in range(20000000)))
>   Access: 175K/sec, presumably, based upon the profile for the other
> array.array
>   Initialization: 6.7s
>
> Any idea why my numpy array access is so slow?
>
>
Without seeing the whole script it is hard to tell. But numpy indexing is
slow and should be avoided when possible.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100206/b3e31be9/attachment.html>


More information about the NumPy-Discussion mailing list