[Numpy-discussion] Performance of the array protocol
Francesc Altet
faltet at carabos.com
Tue Nov 1 03:38:57 EST 2005
Hi,
I'm trying to start using the array protocol for conversion between
Numeric <--> numarray (and newcore in the future), but I'm a bit
disappointed because of its performance. For numarray --> Numeric we
have:
>>> t1=timeit.Timer("num=Numeric.array(na)", "import numarray; import
Numeric; na=numarray.arange(10)")
>>> t1.repeat(3,10000)
[0.59375977516174316, 0.57908082008361816, 0.56574010848999023]
>>>t2=timeit.Timer("num=Numeric.fromstring(na._data,typecode=na.typecode())", "import numarray; import Numeric; na=numarray.arange(10)")
>>> t2.repeat(3,10000)
[0.11653494834899902, 0.1140749454498291, 0.1141819953918457]
i.e. the array protocol seems 5x slower than the fromstring() method.
Conversely, for Numeric --> numarray:
>>> t3=timeit.Timer("na=numarray.array(num)", "import numarray; import
Numeric;num=Numeric.arange(10)")
>>> t3.repeat(3,10000)
[1.3475611209869385, 1.3277668952941895, 1.3417830467224121]
>>>t4=timeit.Timer("na=numarray.array(buffer(num),type=num.typecode(),shape=num.shape)", "import numarray; import Numeric; num=Numeric.arange(10)")
>>> t4.repeat(3,10000)
[0.42027187347412109, 0.41690587997436523, 0.41626906394958496]
in this case, the array protocol is 3x slower than using the buffer
interface.
I'm wondering whether this relatively poor performance in present
implementation of the array protocol is surmountable or is an intrinsic
limitation of it.
Thanks,
--
>0,0< Francesc Altet http://www.carabos.com/
V V Cárabos Coop. V. Enjoy Data
"-"
More information about the NumPy-Discussion
mailing list