no sign() function ?

Pierre-Alain Dorange pdorange at
Wed Dec 24 08:59:16 CET 2008

Steven D'Aprano <steve at> wrote:

> > sign_0 : 0.375
> > sign_1 : 0.444 (+18%)
> > sign_2 : 0.661 (+76%)
> > sign_3 : 0.498 (+33%)
> Looking at those results, and remembering that each time is for one 
> million iterations of one thousand calls each,

one million iteration only, that's enough but yes indeed this function
is fast.

> I'd say that there's so 
> little difference in speed between them, that you should choose whichever
> function is easier to understand.

Yes, you're right. I just made those test for pure intellectual reason.

For me sign_0 is the simplest one to understood. 
So in the domain of my little arcade game, this is what i'll use.
I don't need the accuraccy of sign_1, because in the application i just
need to know if the target is right or left or if the speed direction is
right or left.

> At least until you profile your 
> application and discover that the sign() function is the bottleneck 
> keeping your program slow.

In each frame i'll have to use about 10 to 20 sign() call, so it'll not
be the bottleneck.

Pierre-Alain Dorange        <>

Ce message est sous licence Creative Commons "by-nc-sa-2.0"

More information about the Python-list mailing list