[Numpy-discussion] Simple optimization

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


Colin J. Williams wrote:

> # NumericNumarrayTest.py
> ''' A test, provided by Francesc Altet
>    
> http://sourceforge.net/mailarchive/forum.php?thread_id=6396059&forum_id=4890 
>
>    '''
> 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)
>
> # scipy/Numeric3 added
> 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






More information about the Numpy-discussion mailing list