The full sentence is worth having: “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%.”
The second sentence is almost always omitted in popular usage, which changes the meaning. Knuth is not saying do not optimize. He is saying optimize in response to evidence, in the places where it actually matters. The quote is frequently recruited in defense of code that was never intended to be optimized at all, which is a different argument.
The 97%/3% distinction is also often forgotten: most of the program is not worth optimizing, but a small fraction usually is, and that fraction is worth finding through measurement rather than intuition.
The full sentence is worth having: “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%.”
The second sentence is almost always omitted in popular usage, which changes the meaning. Knuth is not saying do not optimize. He is saying optimize in response to evidence, in the places where it actually matters. The quote is frequently recruited in defense of code that was never intended to be optimized at all, which is a different argument.
The 97%/3% distinction is also often forgotten: most of the program is not worth optimizing, but a small fraction usually is, and that fraction is worth finding through measurement rather than intuition.