[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Limited Range?



On Wed, Nov 04, 2009 at 10:31:24AM -0800, Ian Mallett wrote:
>    On Wed, Nov 4, 2009 at 9:21 AM, James Paige <Bob@xxxxxxxxxxxxxxxxxxx>
>    wrote:
> 
>      x**0.5 is the same as math.sqrt(x)
> 
>    x**0.5 is faster than math.sqrt()
>    Ian

Interesting! You are absolutely right about that.
x**0.5 takes about 1/3 of the time that math.sqrt(x) does.

I wonder why?

(googles)

part of the overhead comes from looking up "sqrt" in the "math" 
namespace. That can be avoided by doing "from math import sqrt"

But even then, sqrt() is still slower because it links to the sqrt() C 
function, whereas x**0.5 uses python's own implementation.

Good to know! Thanks for bringing that to my attention.

---
James Paige