why memoizing is faster

Lie lie.1296 at gmail.com
Sat Mar 26 05:55:45 EDT 2011


On Mar 26, 5:10 pm, Terry Reedy <tjre... at udel.edu> wrote:
> On 3/26/2011 12:17 AM, Stefan Behnel wrote:
>
> > Not "restarted" in the sense that it gets cleaned up, though. The above
> > simply passes an explicit value for it that will be used for the single
> > call.
>
> Which satisfies the time test need, but...
>
>  > Future calls won't be affected.
>
> Good point. If one does fib(10000) and wants to dump the cache without
> dumping all references to the function object, one can currently do
>    fib_iter.__kwdefaults__['_cache'] = [0,1]
> to truly reset the cache, at least with CPython.

Alternatively:

new_cache = [0, 1]
fib_iter(100, new_cache)
fib_iter(200, new_cache)



More information about the Python-list mailing list