When Python outruns C++ ...

Mike Meyer mwm at mired.org
Thu Apr 3 15:13:43 EST 2003


"Anders J. Munch" <andersjm at inbound.dk> writes:
> "Dave Benjamin" <ramen at lackingtalent.com> wrote:
> > In article <b6ckjr$903$1 at panix2.panix.com>, Roy Smith wrote:
> > > 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.
> The downside is that sometimes code is contorted to fit whatever has a
> fast high-level implementation in the current interpreter, instead of
> adapting to the nature of the problem.
> For a Python example, see the Decorate-Sort-Undecorate pattern.  In
> C++ the straightforward and fast solution is to use a suitable
> comparison predicate.  In Python you can do the same, but that's slow,
> and you are left with a choice between clarity and speed.

The statement about the preferred method in C is simply false. Anytime
the "suitable comparison predicate" is sufficiently complex - for
instance, what the unix sort(1) command allows - a DSU that allows
simple comparisons will be faster than a sort with complex
comparisons.

In fact, any time you can simplify the comparison with DSU, the DSU
sort will always perform faster on n objects for sufficiently large n.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.




More information about the Python-list mailing list