[Tutor] finding square roots
Eric Brunson
brunson at brunson.com
Fri Oct 5 22:13:32 CEST 2007
Elaine wrote:
> Does anyone know which is the more efficient way of
> finding a square root in Python:
>
> sqrt(x) or x ** 0.5
>
I dunno, let's check:
>>> import timeit
>>> t = timeit.Timer( "12 ** .5" )
>>> print t.timeit(10000000)
2.29147315025
>>> t = timeit.Timer( "sqrt(12)", "from math import sqrt" )
>>> print t.timeit(10000000)
7.17679214478
Looks like ** is about three times faster than sqrt(), but that could be
the function overhead.
> ???
>
> Thanks,
> Elaine
>
>
>
> ____________________________________________________________________________________
> Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
> http://smallbusiness.yahoo.com/webhosting
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list