A quote from “Python Programming: An Introduction to Computer Science“
We could have taken the square root
using exponentiation **. Using
math.sqrt is somewhat more efficient.
“Somewhat”, but to what extent, and how?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Theoretically, hammar’s answer and duffymo’s answer are good guesses. But in practice, on my machine, it’s not more efficient:
Part of the problem is the
.operation. If you importsqrtdirectly into the namespace, you get a slight improvement.Key word there: slight.
Further testing indicates that as the number gets larger, the benefit you get from using
sqrtincreases. But still not by a lot!