When Python outruns C++ ...

Mike Meyer mwm at mired.org
Fri Apr 4 13:55:30 EST 2003


"Anders J. Munch" <andersjm at inbound.dk> writes:

> "Mike Meyer" <mwm at mired.org> wrote:
> > "Anders J. Munch" <andersjm at inbound.dk> writes:
> > > 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.
> The typical case is a simple projection.  And when it's not you can
> turn it into one by storing or caching the projected value in the
> objects themselves.

Uh - storing or caching the values is a decoration algorithm.

> > 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.
> A comparison predicate in C++ (who said anything about C?) that
> forwards to instance variables simplifies the comparison similarly.

My bad - I tend to merge the two, because I only use either one as
high-level assemblers.

        <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