[Tutor] Caching for speed
rdm at rcblue.com
Mon Nov 26 11:22:26 CET 2007
At 12:39 AM 11/26/2007, Alan Gauld wrote:
>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
>Which will be faster than 0.1 seconds I suspect!
>Or am I missing something?
I should have explained that "print pi" line.
Using <http://py77.python.pastebin.com/m6b2b34b7>, here's the output
for precision = 100:
Enter a positive integer to set precision: 100
The result calculated from the first 8 terms of the series is:
pi to 100 digits is:
Time was 0 seconds
The "print pi" line (line 42) is there to confirm to the user that
the algorithm in fact does compute pi to the requested precision
(i.e., number of digits). Remember, I wrote the script as a demo of
the Chudnovsky algorithm for pi.
More information about the Tutor