Skip to main content
added 22 characters in body
Source Link
user
  • 5.3k
  • 9
  • 54
  • 81

In these micro-benchmarks, math.sqrtmath.sqrt will be slower, because of the slight time it takes to lookup the sqrtsqrt in the math namespace. You can improve it slightly with

 from math import sqrt 

Even then though, running a few variations through timeit, show a slight (4-5%) performance advantage for "x**.5"x**.5

interestinglyInterestingly, doing

 import math sqrt = math.sqrt 

sped it up even more, to within 1% difference in speed, with very little statistical significance.

 

I will repeat Kibbee, and say that this is probably a premature optimization.

In these micro-benchmarks, math.sqrt will be slower, because of the slight time it takes to lookup the sqrt in the math namespace. You can improve it slightly with

 from math import sqrt 

Even then though, running a few variations through timeit, show a slight (4-5%) performance advantage for "x**.5"

interestingly, doing

 import math sqrt = math.sqrt 

sped it up even more, to within 1% difference in speed, with very little statistical significance.

I will repeat Kibbee, and say that this is probably a premature optimization.

In these micro-benchmarks, math.sqrt will be slower, because of the slight time it takes to lookup the sqrt in the math namespace. You can improve it slightly with

 from math import sqrt 

Even then though, running a few variations through timeit, show a slight (4-5%) performance advantage for x**.5

Interestingly, doing

 import math sqrt = math.sqrt 

sped it up even more, to within 1% difference in speed, with very little statistical significance.

 

I will repeat Kibbee, and say that this is probably a premature optimization.

added 193 characters in body
Source Link
Mr_Pink
  • 109.9k
  • 17
  • 287
  • 275

In these micro-benchmarks, math.sqrt will be slower, because of the slight time it takes to lookup the sqrt in the math namespace. You can improve it slightly with

 from math import sqrt 

Even then though, running a few variations through timeit, show a slight (4-5%) performance advantage for "x**.5"

interestingly, doing

 import math sqrt = math.sqrt 

sped it up even more, to within 1% difference in speed, with very little statistical significance.

I will repeat Kibbee, and say that this is probably a premature optimization.

In these micro-benchmarks, math.sqrt will be slower, because of the slight time it takes to lookup the sqrt in the math namespace. You can improve it slightly with

 from math import sqrt 

Even then though, running a few variations through timeit, show a slight (4-5%) performance advantage for "x**.5"

I will repeat Kibbee, and say that this is probably a premature optimization.

In these micro-benchmarks, math.sqrt will be slower, because of the slight time it takes to lookup the sqrt in the math namespace. You can improve it slightly with

 from math import sqrt 

Even then though, running a few variations through timeit, show a slight (4-5%) performance advantage for "x**.5"

interestingly, doing

 import math sqrt = math.sqrt 

sped it up even more, to within 1% difference in speed, with very little statistical significance.

I will repeat Kibbee, and say that this is probably a premature optimization.

Source Link
Mr_Pink
  • 109.9k
  • 17
  • 287
  • 275

In these micro-benchmarks, math.sqrt will be slower, because of the slight time it takes to lookup the sqrt in the math namespace. You can improve it slightly with

 from math import sqrt 

Even then though, running a few variations through timeit, show a slight (4-5%) performance advantage for "x**.5"

I will repeat Kibbee, and say that this is probably a premature optimization.