Donald Knuth wrote “premature optimization is the root of all evil” in 1974, in a paper called “Structured Programming with go to Statements”. It’s high on the leaderboard of the most quoted sentences in our field, and I would wager that only a fraction of the people quoting it have read the paragraph it comes from.

Here it is, with the part I think is important but quite often missed:

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%. A good
programmer will not be lulled into complacency by such reasoning, he will be
wise to look carefully at the critical code; but only after that code has been
identified.