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

faltet at xot.carabos.com faltet at xot.carabos.com
Fri Apr 14 14:36:06 CDT 2006


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.

It seems that NumPy copy() method is almost 3x slower than in numarray:

In [105]: npcopy=timeit.Timer('b=a.copy()','import numpy as
np;a=np.arange(1000000,dtype="Float64")[::10]')

In [106]: npcopy.repeat(3,10)
Out[106]: [0.171913146972656, 0.175906896591186, 0.171195983886718]

In [107]: nacopy=timeit.Timer('b=a.copy()','import numarray as
np;a=np.arange(1000000,type="Float64")[::10]')

In [108]: nacopy.repeat(3,10)
Out[108]: [0.065090894699096, 0.0630550384521484, 0.0626609325408935]

However, a copy without strides performs similarly in both packages

In [127]: npcopy2=timeit.Timer('b=a.copy()','import numpy as
np;a=np.arange(1000000,dtype="Float64")')

In [128]: npcopy2.repeat(3,10)
Out[128]: [0.24657797813415527, 0.24657106399536133, 0.2464911937713623]

In [129]: nacopy2=timeit.Timer('b=a.copy()','import numarray as
np;a=np.arange(1000000,type="Float64")')

In [130]: nacopy2.repeat(3,10)
Out[130]: [0.244544982910156, 0.251885890960693, 0.2419440746307373]

--------------------------------------------

where() seems more than 2x slower in NumPy than in numarray:

In [136]: tnpf=timeit.Timer('np.where(a + b < 10, a, b)','import numpy
as np;a=np.arange(100000,dtype="float64");b=a*2')

In [137]: tnpf.repeat(3,10)
Out[137]: [0.225586891174316, 0.22503495216369629, 0.224209785461425]

In [138]: tnaf=timeit.Timer('np.where(a + b < 2, a, b)','import
numarray as np;a=np.arange(100000,type="Float64");b=a*2')

In [139]: tnaf.repeat(3,10)
Out[139]: [0.108436822891235, 0.1069340705871582, 0.10654377937316895]

However, for where() without parameters, NumPy performs slightly
better than numarray:

In [143]: tnpf2=timeit.Timer('np.where(a + b < 10)','import numpy as
np;a=np.arange(100000,dtype="float64");b=a*2')

In [144]: tnpf2.repeat(3,10)
Out[144]: [0.0759999752044677, 0.0731539726257324, 0.073034048080444336]

In [145]: tnaf2=timeit.Timer('np.where(a + b < 2)','import numarray as
np;a=np.arange(100000,type="Float64");b=a*2')

In [146]: tnaf2.repeat(3,10)
Out[146]: [0.0890851020812988, 0.0853078365325927, 0.085799932479858398]


Cheers,

Francesc




More information about the Numpy-discussion mailing list