Leibniz_Pi.py

Cousin Stanley CousinStanley at HotMail.com
Tue Oct 15 14:25:50 EDT 2002


Thanks to everyone for their interest, replies, and suggetions
with regards to the  Leibniz Pi  approximation ... 

I've been  { OTL :  Out to Lunch }  since I first posted,
and just managed to get back to this today ... 

My primary interest in the algorithm was in its simplicity
in mathematical expression and ease of coding
and thus adaptability to testing easily in Python, 
especially, since the Java version was already available ...  

I stuck a few of the suggestions from your posts
along with a  psyco  binding for each as suggested by David Mertz
into a single test program and came up with the following results ... 

  Compaq 250 MHz  
  Win98 1st Ed.
  Python 2.2.1

    Approximate  Pi  via Leibniz Sequence

   J. Lindström :  7.96000003815 Seconds ......... Original Java to Python Conversion
                           :  1.92999994755 Seconds psyco

   B. Höllmann  :  3.79000008106 Seconds ......... Numeric Version
                          :  2.95999991894 Seconds psyco

         T. Heller :  5.53999996185 Seconds ........... Separate Signs
                         :  1.26999998093 Seconds psyco

    M. Fletcher :  6.59000003338 Seconds ......... xrange Version
                         :  1.31999993324 Seconds psyco

            Terms :  1000000

                  Pi1 :  3.14159165359
                  Pi2 :  3.14159165359
                  Pi3 :  3.14159165359
                  Pi4 :  3.14159165359

          math.pi :  3.14159265359

ALL suggestions seem to provide fairly significant improvements 
in performance over the original  Python  version 
and the  psyco  bindings provide further marked improvement in each case ... 

After including some actual timer code in the Java version,
I found that the  Java SDK 1.4  version for  1 million  terms 
runs in 0.330 Seconds on this machine, which is a still a little quicker 
than the  psyco  bound  Python  versions, but not by much ...
 
Java version test code ... 
http://fastq.com/~sckitching/Leibniz_Pi.java

Python version test code ... 
http://fastq.com/~sckitching/Leibniz_Pi_Test.py

Thanks again for the info ... 

Stanley C. Kitching




More information about the Python-list mailing list