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

Re: [pygame] Limited Range?



Oops, yes, I forgot the "abs", but as noted, the speed difference is
negligible.

On Wed, 4 Nov 2009 11:01:53 -0800, James Paige <Bob@xxxxxxxxxxxxxxxxxxx>
wrote:
> 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.

Looks like another quirk of Python exposed. Someone on this list also
helped figure out that Python recycles short strings as the same object, so
that for strings less than around 20 characters:
>>> a = "spam"
>>> b = "spam"
>>> a is b
True