[SciPy-user] Speed differences in sqrt calculation: what is good to know

Matthieu Brucher matthieu.brucher at gmail.com
Wed Jun 11 14:54:48 EDT 2008


Hi,

Don't forget that numpy's sqrt and scipy's sqrt are not optimized towards
single computations.
If you really want to compare them, time the square root of 10000 elements.

Matthieu

2008/6/11 Ivo Maljevic <ivo.maljevic at gmail.com>:

> Based on comments from Gael Varoquaux and David Cournapeau , I did the
> execution time test.
> At least for me, it is clear that if the number is a real scalar, AND the
> expected result is also real,
> the best way is to call the math version of sqrt() function. The
> differences are more than significant, as you can see:
>
> In [3]: from math import sqrt as msqrt
> In [4]: from numpy import sqrt as nsqrt
> In [5]: from scipy import sqrt as ssqrt
>
> In [6]: %timeit msqrt(3.14)
> 1000000 loops, best of 3: 479 ns per loop
>
> In [7]: %timeit nsqrt(3.14)
> 100000 loops, best of 3: 10.8 µs per loop
>
> In [8]: %timeit ssqrt(3.14)
> 10000 loops, best of 3: 74.5 µs per loop
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>


-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080611/f5c95488/attachment.html>


More information about the SciPy-User mailing list