When Python outruns C++ ...

Dave Benjamin ramen at lackingtalent.com
Tue Apr 1 13:42:08 EST 2003


In article <b6ckjr$903$1 at panix2.panix.com>, Roy Smith wrote:
> Mike Meyer  <mwm at mired.org> wrote:
>> The trick to getting good performance out of interpreted languages is
>> doing things to take advantage of those libraries.
> 
> This is a very true statement, and one which I think is
> under-appreciated by a lot of people.
> 
> ...
> 
> The bottom line is exactly what Mike said: in interpreted languages,
> the more you can push down into the libraries and interpreter core,
> the better off you are most of the time.  And profiling helps too :-)

This has been my experience as well. It is a very gratifying discovery,
IMHO, because it encourages a less-is-more style of programming where you
say what you mean, and little else.

In general, when concise, declarative code tends to execute faster than
verbose imperative code, that is a good sign for a high-level language.

The presence of well-optimized core libraries with simple interfaces (like
Python's lists and dictionaries) encourages reuse, readability, and
efficiency, all at once.

It does require a shift in thinking for those accustomed to C++ or Java
programming. For instance, iterating through strings character-by-character
is often very efficient in these languages, but in Python you're usually
better off thinking in terms of splits, joins, replacements, regexes, etc.
Profiling is the only surefire way to know.

Dave




More information about the Python-list mailing list