Warnings killing my performance

Kylotan kylotan at hotmail.com
Sat Feb 7 23:19:26 CET 2004

mwilson at the-wire.com (Mel Wilson) wrote in message news:<cFQJAls/KbZC089yn at the-wire.com>...

>    I notice that you're effectively cubing x, so you could
> only keep 10 bits of it and be sure of avoiding 32-bit
> overflow.

I'm not sure why you say that. If I feed '10' into the formula in
question I'll get something much larger than 1000 out!

>  Maybe a linear pseudo-random formula would save
> some trouble.  But it appears that random.randint also
> generates invisible warnings.

Well, I changed the whole function to the following:

    return rnd.uniform(-1.0, 1.0)

Where rnd is an instance of Random(). This is a little quicker, and
doesn't throw any warnings (visible or otherwise). I just have to hope
the random.uniform implementation doesn't change any time soon.

I would also hope that someone will find a way to remove that hidden
warning from randint because it seems to be an unnecessary performance
hit on what is otherwise a fairly fundamental function.

> The warnings go away with
>         x = long(x << 13) ^ x

So do the results I'm trying to get ;)

Ben Sizer

More information about the Python-list mailing list