Skip to content
CONTACT

Premature optimisation

PROGRAMMING AND BUGS

Premature optimisation is the root of all evil (or nearly) in programming: first make it work, then measure where it is slow.

— Donald Knuth, Structured Programming with go to Statements, Computing Surveys, 1974 (Knuth later also traced it back to Tony Hoare)
VIDEO.EXE16:9

There's a type of programmer who spends three days making a function lightning fast when it is called once a year, on 1 January, to print a New Year greeting. He gains four milliseconds. He celebrates as if it were the Moon landing.

The point of the phrase is common sense: you don't know where the slowness is until you measure. Optimising blindly makes the code unreadable and leaves the real bottleneck untouched, which is usually a query run inside a loop.

My uncle optimised his cellar: shelves in alphabetical order, indexes, a cache of his favourite bottles. Then he realised the door was locked and the key was in the cellar. Access time was infinite, but very well organised.