When Python outruns C++ ...

Alex Martelli aleax at aleax.it
Tue Apr 1 11:23:24 CEST 2003


Max Khesin wrote:

> I personally question such beliefs 'a priori' from language design
> perspective but justify them retrospectively in terms of soft
> engineering/economis. What I mean is the following: a language that gives
> you more of an access to the machine architecture (whether you like it or
> not) is capable of no less optimization (and most likely more) than a
> language that is further removed from it. Python vs. C is a particularly
> poigniant example since Python is a C program. On a minute level such C++

No more poignant than C vs machine code.  The tradeoff is similar.  Yes,
in theory, if you have unbounded development time available, you can
always write machine-code programs that will outperform C or C++ ones,
and can always wite C or C++ programs that will outperform Python ones
(unless, perhaps, the Python ones are using machine code that your C
or C++ compiler cannot generate).  If there are any bounds on the time
you can spend developing your programs, then the theoretical situation
is not so clear and sharp any more (partly depending on what set of
already-written code you can be thought to have at hand in each case).

The theory is only important up to a point.  In _practice_, a mix of
SOME Python, SOME C/C++, and, yes, even some machine code when that's
appropriate (check out GMP implemented in C vs machine code, most
particularly on an Athlon... if you do heavy multiprecision arithmetic,
the performance difference is important!), is almost invariably the
optimal choice -- main exception being when the target machine just
doesn't have the needed resources (e.g. some embedded development),
mostly memory, in which case using just C+machine code, or even just
machine code in some cases, CAN be pragmatically optimal.


Alex





More information about the Python-list mailing list