# [Numpy-discussion] Simple optimization

Travis Oliphant oliphant at ee.byu.edu
Thu Oct 6 15:15:40 EDT 2005

```Colin J. Williams wrote:

> # NumericNumarrayTest.py
> ''' A test, provided by Francesc Altet
>
>
>    '''
> from timeit import Timer
> setup = "import Numeric; a = Numeric.arange(2000);a.shape=(1000,2)"
> print 'Timer-Numeric23.8:', Timer("for i in range(len(a)): row=a[i]",
> setup).timeit(number=100)
>
> #
> setup = "import numarray; a = numarray.arange(2000);a.shape=(1000,2)"
> print 'Timer-numarray1.3.3:', Timer("for i in range(len(a)):
> row=a[i]", setup).timeit(number=100)
>
> setup = "import scipy.base; a = scipy.base.arange(2000);a.shape=(1000,2)"
> print 'Timer-Numeric3:', Timer("for i in range(len(a)): row=a[i]",
> setup).timeit(number=100)
>
> RESULTS:
> >pythonw -u "NumericNumarrayTest.py"

> Timer-Numeric23.8: 0.179712784725
> Timer-numarray1.3.3: 0.21674933546
> Timer-Numeric3: 0.253077136899

After a simple optimization in the array_subscript function (to check
for scalar selection up front): new results are (for 1000 runs on my
system):

Numeric:  0.56431102752685547
numarray:  1.0897960662841797
scipy:    0.57508182525634766    (it's now executing nearly the
identical code as Numeric)

Any more optimization ideas?

-Travis

```