[Baypiggies] PyCon 2007
bsergean at gmail.com
Sat Feb 24 18:16:38 CET 2007
Quite interesting, and for those who'd like to go farther on the
'Assuming an infinte number of points the ratio of points may be used
instead of the areas, so: '
¹ = 4 numberof pointsinside / totalnumberof points
Here is an explanation in french
Le 22 fvr. 07 10:36, Ken Seehart a crit :
> Hello from Texas!
> Just finished Faster Python Programs through Optimization and
> Extensions I tutorial.
> Started a little slowly with comparisons of list joins vs
> sequential string concatenation, etc, while showing how to use
> time.clock() to compare performance.
> Started getting interesting with some real tools, like Numpy.
> Most valuable insight for me: look at Psyco. This has got to be
> the quickest way to get a performance boost (about 4x in some
> examples) on Intel processors without any effort. Two lines of
> code will often do the trick.
> import psyco
> psyco.full() # converts and binds all of your functions to native code
> Also looked at pyrex, a custom language which makes it pretty easy
> way to rewrite existing python code and wrap existing C/C++ code to
> be compiled with a C compiler. Seems easier than boost or swig
> (except perhaps for large API libraries), and much easier than hand
> coding C extensions.
> # file: mc_pi_pyrex_fast.pyx
> cdef extern from "math.h": #1
> double sqrt(double x) #2
> cdef extern from "stdlib.h": #3
> int rand() #4
> int RAND_MAX #5
> def piPyrex(int n):
> cdef int count_inside, count #6
> cdef float x, y #7
> count_inside = 0
> for count from 0 <= count < n: #8
> x = rand() #9
> y = rand()
> d = sqrt(x*x + y*y) #10
> if d < RAND_MAX: #11
> count_inside = count_inside + 1
> return 4.0 * count_inside / n
> Covered ctypes for yet another way to wrap a DLL or shared library.
> Compared a variety of tools for relative speed (see the pdf).
> - Ken Seehart
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Baypiggies