Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“Premature optimization is the root of all evil” is Donald E. Knuth’s warning against spending time improving code before evidence shows where performance matters. He was not arguing against optimization: he urged programmers to ignore small efficiencies most of the time and focus on the critical parts when measurement identifies them.

Who said “premature optimization is the root of all evil”?

Computer scientist Donald E. Knuth used the idea in two related works published in 1974: his paper “Structured Programming with go to Statements” and his Turing Award lecture, published as “Computer Programming as an Art.” The familiar one-line maxim is a shortened version of a longer point.

In the lecture, Knuth wrote that programmers had spent too much time worrying about efficiency “in the wrong places and at the wrong times,” then added “or at least most of it” after the phrase “premature optimization is the root of all evil.” That qualification matters: the target is misplaced effort, not performance work itself.

What did Knuth mean by the 97% rule?

In the 1974 paper, Knuth wrote: “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 97% and 3% are a rhetorical rule of thumb, not a measured industry statistic or universal law. The practical message is to avoid polishing code that does not meaningfully affect the work your program needs to do, while staying alert to genuinely critical sections.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When is optimization premature?

Optimization is premature when you add complexity based mainly on intuition—before a correct, representative baseline exists or before measurement shows that a section of code is worth improving. A hunch may be a useful reason to investigate, but it is not proof that the suspected code is the bottleneck.

There is a real cost to optimizing the wrong thing. Knuth’s discussion notes that attempts to improve noncritical code can harm debugging and maintenance. A change that makes a small operation faster may be a poor trade if it makes the program harder to understand, verify, or safely change.

How to optimize without guessing

  1. Build a correct, understandable baseline. Make sure the program produces the right result before judging its speed. Record the workload and conditions you care about so you have something meaningful to compare.
  2. Measure representative work. Use a profiler or equivalent instrumentation on realistic inputs. Stanford’s performance-analysis teaching material places profiling alongside optimization for a reason: measurement helps identify where execution time is actually going.
  3. Choose a demonstrated bottleneck. Focus on a hot path or other measured constraint that materially affects the workload, rather than making scattered changes to code that merely looks inefficient.
  4. Make a targeted change and remeasure. Compare the revised program with the baseline under the same relevant conditions. Keep the change only if it improves the outcome that matters and does not undermine correctness.
  5. Account for maintenance cost. Weigh the measured benefit against added complexity, readability, debugging effort, and the cost of future changes. A tiny speed gain may not justify harder-to-maintain code.

Is premature optimization always bad?

No. Knuth’s point is not to postpone every performance decision or to refuse optimization. It is to act at the right time and place, based on evidence. If measurement shows that a section of code is critical to a real workload, improving it is exactly the kind of opportunity his “critical 3%” passage says not to miss.

Likewise, the maxim does not mean that every design choice must wait for a profiler. It distinguishes routine choices that keep an implementation clear from efforts to squeeze speed out of code without knowing whether that effort matters. Measure when performance is a concern; optimize where the results justify the trade-off.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Should you profile before optimizing?

For performance changes whose value is uncertain, profiling—or another suitable form of measurement—is the practical way to locate the work worth optimizing. It turns “this seems slow” into evidence about the workload and helps you check whether a change improved the intended outcome. The profile is not a substitute for judgment: you still need to decide whether the gain is meaningful and worth any loss in clarity or maintainability.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.