[Baypiggies] PyCon 2007

Ken Seehart ken at seehart.com
Thu Feb 22 19:36:19 CET 2007


Hello from Texas!

Just finished /*Faster Python Programs through Optimization and 
Extensions I* 
<http://www.python-academy.de/download/pycon/fasterpython_I.pdf> /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 
<http://numpy.scipy.org/>.

Most valuable insight for me: look at Psyco 
<http://psyco.sourceforge.net/>.  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 
<http://www.python-academy.de/download/pycon/fasterpython_I.pdf>).

- Ken Seehart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/baypiggies/attachments/20070222/5bc43543/attachment.html 


More information about the Baypiggies mailing list