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] Power optimization branch merged to Numpy trunk
by Hugo Gamboa other posts by this author
Mar 8 2006 4:25AM messages near this date
[Numpy-discussion] Power optimization branch merged to Numpy trunk | [Numpy-discussion] numpy doc strings - a tool to list problem cases
Since you are mentioning some improvements (I have confirmed them!) I would
like to ask what code are you using for benchmarking numpy.

I wanted to know what code was faster:

sum(|x|)/N or sqrt(sum(x**2))/sqrt(N)

I wrote a timeit test and discovered that using the function dot(x,x) to
compute sum(x**2) gives the best result and is one order of magnitude faster
than sum(|x|).
I found that sum and absolute are approx. 5 times slower than dot. I also
noticed that the std function is slightly slower than a python
implementation code.

These are the results for some operations in a randn vector of size 1000:


      48.9+-22.6us: np.dot(v,v)
     628.8+-87.3us: np.sum(np.absolute(v))
     518.3+-65.9us: np.sum(v*v)
     118.0+-1.4us: v*v
     234.4+-56.5us: np.absolute(v)
     234.3+-56.2us: v.sum()
    1175.2+-58.6us: v.std()
     969.6+-77.4us: vv=np.mean(v)-v;(np.sqrt(np.dot(vv,vv)/(len(v)-1)))


The code for timming the numpy operations:

#################

import timeit
import numpy as np

p= """
import numpy as np
vsize=1000
v=np.randn(vsize)
"""

vs=[
'np.dot(v,v)',
'np.sum(np.absolute(v))',
'np.sum(v*v)',
'v*v',
'np.absolute(v)',
'v.sum()',
'v.std()',
'vv=np.mean(v)-v;(np.sqrt(np.dot(vv,vv)/(len(v)-1)))']

ntests=1000
tries=5


for s in vs:
    t = timeit.Timer(s,p)
    r=(np.array(t.repeat(tries,ntests))/ntests) * 10.0e6
    print ("%10.1f+-%3.1fus: %s " % (np.mean(r), np.std(r) ,s))

#################

If some one have a complete benchmarking set of functions I would like to
use them.

Thanks.

Hugo Gamboa
Attachments:
unknown1
unknown2

Thread:
David M. Cooke
Hugo Gamboa

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