scripting languages vs statically compiled ones

Patrick Maupin pmaupin at speakeasy.net
Sun Oct 31 00:34:56 EDT 2004


kosh <kosh at aesaeion.com> wrote:

<a lot of good stuff about making Python faster>

In addition to your points and Alex's additions, I would add (as part
of your step 4): To make Python faster (drumroll...) CACHE
EVERYTHING!!!

The concept of caching goes by various names (e.g. memoize) depending
on the exact form it takes, but in any case it is usually _much_
easier to do simply and correctly in Python than in almost any other
language, and can sometimes produce dramatic results.

As an example, I wrote an assembler/linker combination in Python (with
a little bit of Pyrex and a tiny bit of C for the scanner).  When I
started out, it was much slower than the C legacy system it replaced. 
Now, it is much faster, by a factor of around 4x for a full build.  It
is also much nicer, catches more errors, has a more flexible syntax,
etc.

In C, there is no way I would have been able to get the semantics
right for usefully caching the results of partial evaluation of
include files, but in Python it is a snap.  (Note that I did not
assert that it is not possible to do this in C, merely that _I_ would
have been incapable of doing it in the time I would have been willing
to spend on the task.)  I also cache the object files (which are
merely pickles) in preparation for doing a link, the source modules in
preparation for doing a listing output (which can be done as a
relative listing before the link, or an absolute listing after the
link), and anything else I can think of.

The Python version occupies a working set of around 75MB when it runs,
compared to about 4MB for the C version.  Good programmers have always
known about time vs. memory tradeoffs, but the informed use of Python
in conjunction with the staggering amount of memory available on
today's average PC can produce truly startling results.

Regards,
Pat



More information about the Python-list mailing list