no sign() function ?
steve at REMOVE-THIS-cybersource.com.au
Wed Dec 24 08:19:48 CET 2008
On Tue, 23 Dec 2008 14:36:53 +0100, Pierre-Alain Dorange wrote:
> 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%)
Looking at those results, and remembering that each time is for one
million iterations of one thousand calls each, I'd say that there's so
little difference in speed between them, that you should choose whichever
function is easier to understand. At least until you profile your
application and discover that the sign() function is the bottleneck
keeping your program slow.
More information about the Python-list