no sign() function ?

Pierre-Alain Dorange pdorange at pas-de-pub-merci.mac.com
Tue Dec 23 08:36:53 EST 2008


Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> wrote:

> But this is just duplicating what timeit already does. Trust me, learn to
> use it, you won't be sorry. Here's a trick that took me a long time to
> learn: instead of copying your functions into the setup code of timeit,
> you can just import them.

Thanks for the advise, i made the test using timeit and your very
interesting method to import... Now i know how to use timeit simply ;-)

New results on 1000 float values randomized from -500.0 to +500.0.
Each test is timeit(1000)

sign_0 : 0.375
sign_1 : 0.444 (+18%)
sign_2 : 0.661 (+76%)
sign_3 : 0.498 (+33%)

It seems it don't change the relative results between the methods.
Using timeit make measure accurate and remove print/range footprints.

I also try Arnaud's proposition, it make sign_0 just a little better
(-1%)

-- 
Pierre-Alain Dorange        <http://microwar.sourceforge.net/>

Ce message est sous licence Creative Commons "by-nc-sa-2.0"
        <http://creativecommons.org/licenses/by-nc-sa/2.0/fr/>



More information about the Python-list mailing list