ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
Re: [Numpy-discussion] Is sum() slow?
by Travis Oliphant other posts by this author
Mar 7 2006 10:38AM messages near this date
[Numpy-discussion] Is sum() slow? | Re: [Numpy-discussion] Is sum() slow?
Mads Ipsen wrote:

> Hi,
> 
> Sorry if this is a double post - unsure if it made it the first time:
> 
> Here are some timings that puzzle me a bit. Sum the two rows of a 2xn
> matrix, where n is some large number
> 
> python -m timeit -s "from numpy import array,sum,reshape; x =
> array([1.5]*1000); x = reshape(x,(2,500))" "x.sum(0)"
> 10000 loops, best of 3: 36.2 usec per loop
> 
> python -m timeit -s "from numpy import array,sum,reshape; x =
> array([1.5]*1000); x = reshape(x,(2,500))" "x[0] + x[1]"
> 100000 loops, best of 3: 5.35 usec per loop
>   
> 

This is probably reasonable.  There is overhead in the looping construct 
(basically what happens is that the first element is copied into the 
output and then a function called --- which in this case has a loop of 
size 1 to compute the sum).   

This is then repeated 500 times.  So, you have 500 C-function pointer 
calls in the first case.
In the second case you have basically a single call to the same function 
where the 500-element loop is done.

I'm a little surprised that Numeric is so much faster for this case as 
you show later.   The sum code is actually add.reduce... which uses a 
generic reduction concept in ufuncs.  It has overhead over what you 
might do using some less general approach.

If anyone can figure out how to make the NOBUFFER secion in 
GenericReduce faster in ufuncobject.c it will be greatly welcomed.

Speed improvements are always welcome.

-Travis




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Thread:
Mads Ipsen
Travis Oliphant
Sasha
Alexander Belopolsky

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved