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

2008-08-03 Thread Steven D'Aprano
On Sun, 03 Aug 2008 09:46:45 -0500, Rob Williscroft wrote: > Steven D'Aprano wrote in news:[EMAIL PROTECTED] > in comp.lang.python: > >>> 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

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

2008-08-03 Thread Rob Williscroft
Steven D'Aprano wrote in news:[EMAIL PROTECTED] in comp.lang.python: >> 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 calle

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

2008-08-03 Thread ssecorp
I think you are confusing 2 people in this thread but that doesn't really matter. What surprised me was that I didn't think fib would benefit from memoization because it didn't repeat the same calculations. fibmem without memoization is the classic naive implementation that grows exponentially and

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

2008-08-02 Thread Steven D'Aprano
On Sat, 02 Aug 2008 16:14:11 -0500, Rob Williscroft wrote: > Stefaan Himpe wrote in news:[EMAIL PROTECTED] in > comp.lang.python: > >> Nothing weird about this ... >> The difference will become larger as your input value becomes larger. >> >> You can easily understand why if you try to calculate

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

2008-08-02 Thread Steven D'Aprano
On Sat, 02 Aug 2008 06:02:02 -0700, ssecorp wrote: > I am not clear about the results here. > > > from timeit import Timer > import Decorators > > def fib(n): > a, b = 1, 0 > while n: > a, b, n = b, a+b, n-1 > return b [...] > s = 100 > > t1 = Timer('fib(s)', 'from __main

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

2008-08-02 Thread Rob Williscroft
Stefaan Himpe wrote in news:[EMAIL PROTECTED] in comp.lang.python: > Nothing weird about this ... > The difference will become larger as your input value becomes larger. > > You can easily understand why if you try to calculate fib(10) by hand, > i.e. work through the algorithm with pencil and p

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

2008-08-02 Thread Stefaan Himpe
Nothing weird about this ... The difference will become larger as your input value becomes larger. You can easily understand why if you try to calculate fib(10) by hand, i.e. work through the algorithm with pencil and paper, then compare the work you have to do to the memoized version which just

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

2008-08-02 Thread ssecorp
I am not clear about the results here. from timeit import Timer import Decorators def fib(n): a, b = 1, 0 while n: a, b, n = b, a+b, n-1 return b @Decorators.memoize def fibmem(nbr): if nbr > 1: return fibmem(nbr-1) + fibmem(nbr-2) if nbr == 1: return