Doubt C and Python

Delaney, Timothy (Tim) tdelaney at avaya.com
Wed Aug 24 00:01:56 EDT 2005


Terry Hancock wrote:

>        * The claim that a Human can optimize code better than
>           the compiler assumes a very smart and talented Human,
>           and/or a very dumb compiler.  Compilers are getting smarter,
>           and since a lot more people find the need to program, the
>           average programmer is not that talented. I'm pretty I'm
>           not, for example -- I'll take my chances with the compiler.

More importantly IMO is that humans cannot effectively optimise code
without profiling - and compilers are not very good at optimising poor
algorithms either. Humans are *really* bad at guessing where bottlenecks
are.

I had a case recently where the *major* performance bottleneck in a
(Java) system was ... equals() and hashCode(). These objects were being
used in lots of hash maps and similar things. The absolute best
performance improvement I was able to make was to cache the hash code,
and reduce the number of times that the expensive parts of the equals()
comparison were called.

It's a lot easier to refactor sub-optimal code in Python than in most
other languages. This is tied directly to the fact that it's easier (and
shorter) to express many concepts/algorithms in Python than in other
languages. This further contributes to it being more fun to code in
Python.

Tim Delaney



More information about the Python-list mailing list