Profiling weirdness: Timer.timeit(), fibonacci and memoization

Rob Williscroft rtw at
Sun Aug 3 16:46:45 CEST 2008

Steven D'Aprano wrote in news:00a529cc$0$20316$c3e8da3 at in 

>> So the question is: whats going on with timeit.Timer ?
> As far as I can see, nothing. I think you have misunderstood the results 
> you got.

No, the answer is that is it repeats a million times.  It might better be
called repeat_one_million_times().

Or put another way, myself and the OP misinterpreted what the call 
t1.repeat( number = 1 ) did.

its a confusing API.

For the OP:

The call t1.timeit() is equivalent to t1.repeat( number = 1000000 ).

So it bennefits from memoization because the call *is* repeated, not
just called once like you intended.


More information about the Python-list mailing list