[Tutor] Caching for speed

Alan Gauld alan.gauld at btinternet.com
Mon Nov 26 09:39:00 CET 2007


While the speed up due to caching is interesting I'm not sure
what your code is supposed to be doing but it looks to me
like you are effectively doing this:

from mpmath import pi
# long pause
print pi

Which will be faster than 0.1 seconds I suspect!
Or am I missing something?

Alan G.

"Dick Moores" <rdm at rcblue.com> wrote in message 
news:20071126025334.A9A0C1E4005 at bag.python.org...
> Caching for speed is a concept brand new to me, and there's a 
> remarkable example in a thread on the python-list. I thought some 
> readers of this list might find it instructive. However, to run the 
> scripts you'll need mpmath. < http://code.google.com/p/mpmath/>
> Begin by jumping in toward the end of the thread:
> < 
> http://mail.python.org/pipermail/python-list/2007-November/466662.html >
> Note Fredrik Johansson's function f() that he suggests could greatly 
> speed up my demo of the amazing Chudnovsky algorithm for pi, at < 
> http://python.pastebin.com/f4410f3dc>.
> I didn't understand what to do with it, so I ask, < 
> http://mail.python.org/pipermail/python-list/2007-November/467148.html 
>  >. But see the revision I did make, < 
> http://py77.python.pastebin.com/f48e4151c>
> And his revision of that, < 
> http://py77.python.pastebin.com/m6b2b34b7>.
> As for the speed-up on my computer due to the caching done by f(): < 
> http://py77.python.pastebin.com/f48e4151c> takes 151 secs for 2000 
> digits of pi; < http://py77.python.pastebin.com/m6b2b34b7> takes 0.4 
> secs!
> Dick Moores


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list