When Python outruns C++ ...

Robin Becker robin at jessikat.fsnet.co.uk
Thu Apr 3 01:07:14 CEST 2003

In article <b6fmcq$dh0$1 at panix2.panix.com>, Roy Smith <roy at panix.com>

>People have been commiting crimes against good design in the name of
>efficiency since punchcard days.  When I first learned C, it was on a
>pdp-11, where the compiler could put three variables per function in
>fast registers.  My major goal in refactoring (although we didn't call
>it that in those days) was to design functions that made extensive use
>of no more than three integers or pointers.
>Just a couple of weeks ago, I let the efficiency bug bite me and spent
>two days totally tearing apart a C++ class to make it use a different
>set of STL containers.  The savings?  I turned a rarely-used linear
>operation (where N <= 24 most of the time) into a constant-time
>operation.  Totally meaningless to overall performance, but once the
>bug bit, it was hard to stop myself :-)
>The dark side of the force is seductive.  It tries to make us
>efficient, even at the cost of clarity and maintainability.  In that
>way lies bit-twiddling and assembler language and soldering irons.  We
>must be diligent in our fight against it.

The Python community sometimes has the efficiency bug. As examples the
desire to optimize global access (ie forbidding 'from module import *'
in inner scopes) and more recently the proposal to inhibit shadowing of
builtin functions in certain circumstances. It seems people never learn
to make regularity a priority. Nobody uses those special cases anyhow
etc etc

Interestingly attempts to get an integer for loop (without range/xrange)
are met with extreme disapproval by the language gurus and the fastest
looping constructs of all map, filter et al are considered bad form.

Robin Becker

More information about the Python-list mailing list