[Numpy-discussion] Is sum() slow?
Alexander Belopolsky
alexander.belopolsky at gmail.com
Wed Mar 8 19:31:02 CST 2006
On 3/7/06, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> ...
> I'm a little surprised that Numeric is so much faster for this case as
> you show later.
>
Here is another puzzle:
> python -m timeit -s "from Numeric import zeros,sum; x = zeros((2,500),'f')" "sum(x,0)"
100000 loops, best of 3: 6.05 usec per loop
> python -m timeit -s "from Numeric import zeros,sum; x = zeros((500,2),'f')" "sum(x,1)"
10000 loops, best of 3: 26.8 usec per loop
> python -m timeit -s "from numpy import zeros; x = zeros((2,500),'f')" "x.sum(0)"
10000 loops, best of 3: 22.8 usec per loop
> python -m timeit -s "from numpy import zeros; x = zeros((500,2),'f')" "x.sum(1)"
10000 loops, best of 3: 23.6 usec per loop
Numpy and Numeric perform very similarly when reducing along the second axis.
> If anyone can figure out how to make the NOBUFFER secion in
> GenericReduce faster in ufuncobject.c it will be greatly welcomed.
Here is my $.02:
<http://projects.scipy.org/scipy/numpy/wiki/PossibleOptimizationAreas/ReduceDiscussion>
BTW, I've tried to take loop->... redirections out of the loop: no
effect with gcc -O3 .
More information about the Numpy-discussion
mailing list