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

Ivo Maljevic ivo.maljevic@gmail....
Wed Jun 11 10:48:32 CDT 2008

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080611/b1d1fca0/attachment.html 

More information about the SciPy-user mailing list