Section notes: Week 13

CS 164, Fall 2005

General

Optimization EC

Role of optimization

Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and such attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

Yet we should not pass up our opportunities in that critical 3%. Good programmers will not be lulled into complacency by such reasoning, they will be wise to look carefully at the critical code; but only after the critical code has been identified. ... After working with such tools for seven years, I've become convinced that all compilers written from now on should be designed to provide all programmers with feedback indicating what parts of their programs are costing the most; indeed, this feedback should be supplied automatically unless it has been specifically turned off.

-- D. Knuth, Structured Programming with go to statements (1974), reproduced in Literate Programming (1992).

MJ optimization ideas

More interesting (non-MJ) optimizations