[SciPy-dev] Indexing array performance

Travis Oliphant oliphant.travis at ieee.org
Sat Dec 31 15:34:48 CST 2005


Francesc Altet wrote:

>Hi,
>
>I'm doing some timings on array indexing feature. It's quite shocking
>to me that, provided empty() and arange() are faster in scipy_core
>than its counterparts in numarray:
>
>In [110]: t1 = timeit.Timer('a=empty(shape=10000);a=arange(10000)','from 
>scipy.base import empty, arange')
>
>In [111]: t1.repeat(3,10000)
>Out[111]: [0.74018502235412598, 0.76141095161437988, 0.71947312355041504]
>
>In [112]: t2 = timeit.Timer('a=array(None,shape=10000);a=arange(10000)','from 
>numarray import array, arange')
>
>In [113]: t2.repeat(3,10000)
>Out[113]: [2.3724348545074463, 2.4109888076782227, 2.3820669651031494]
>
>however, the next code seems to be slower in scipy_core:
>
>In [114]: t3 = timeit.Timer('a=empty(shape=10000);a[arange(10000)]','from 
>scipy.base import empty, arange')
>
>In [115]: t3.repeat(3,1000)
>Out[115]: [3.5126161575317383, 3.5309510231018066, 3.5558919906616211]
>
>In [116]: t4 = timeit.Timer('a=array(None,shape=10000);a[arange(10000)]','from 
>numarray import array, arange')
>
>In [117]: t4.repeat(3,1000)
>Out[117]: [2.0824751853942871, 2.1258058547973633, 2.0946059226989746]
>  
>
I added a special-case for 1-d indexing that goes through the same code 
as a.flat would.  The result seems to show a nice speed up for your test 
case.

This is not to say that the indexing code could not be made faster, but 
that would require more study.  Right now, the multidimensional indexing 
code is fairly clean as it uses the abstraction of an iterator (which 
also makes it hard to figure out how to make it faster).  I've been 
curious as to how fast the result is. 

The results on 2-d indexing are encouraging.  They show the scipy_core 
code to be faster than the 2-d indexing of numarray (as far as I can 
tell).   Of course these things can usually be made better, so I'm 
hesitant to say we've arrived. 

-Travis






More information about the Scipy-dev mailing list