benchmarks and questions for new python programmer

Peter Hansen peter at engcorp.com
Sun May 16 23:03:04 EDT 2004


stormslayer wrote:

> Benchmarks (for the paramter settings in the file):
> 
> C++builder 6.0: 3 seconds
> Perl (ActivePerl 5.6.1.638): 14 seconds
> Python (ActivePython 2.3.2 Build 232): 1 minute 13 seconds
> 
> Note that I didn't fiddle overmuch with any of the programs -- each
> one took about 15 minutes to bang out on the keyboard.  I'm hoping
> that there is some obvious mistake in the way I used something in
> python to account for the speed differential.  It seems like a really,
> really nice language, but orders of magnitude slower than C/C++ and a
> 5x slowdown over Perl seems abusive...

I haven't taken the time to do more than glance at your
program, but I'll note the following things, in no particular
order.

1. Using your first Python program as anything more than a
learning experience would be nuts.  It's highly likely,
in my experience with C/C++ programmers switching to
Python, that your code is more like C and less like Python
and therefore doesn't take much advantage of Python's
strengths.

2. Psyco can provide a very large speedup for many Python
programs, with little or no effort required.

3. "Orders of magnitude" is not likely quite right.  It might
be up to two (decimal) orders of magnitude slower for certain
very rare problems, but is probably closer to one order of
magnitude slower, and possibly less than that in many cases.

4. Python is about as fast as Perl in general.  That you had
a 5x slowdown suggests either that your benchmark exercises
one of the few areas where Perl is highly specialized and
optimized in ways Python cannot be, or (more likely) that
your first Python code is very "un-Pythonic" and therefore
shouldn't be taken as typical.

5. Do a quick search for "Python optimization" and look at
the first handful of links, including Guido's "Optimization
Anecdote", and implement some of the suggestions there.

-Peter



More information about the Python-list mailing list