1
votes

Knuth said: We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil

I’m curious how he came up with 97%. Could someone please share something about this?

UPDATE: The problem is: This sentence is written in a research paper, how come a subjective statement get accepted in such formal document?

8
Notice the big difference between "say about 97%" and "it is a fact that 97%". - Fredrik
I'm pretty sure in the paper he wrote afterwards, he explained that you should roll 5d20 whenever you think about premature optimization, then only go ahead if you roll 98 or higher. - Mark Rushakoff
@Mark, he said 97%. Your die roll would give 99.99934375%. Knuth would know to use percentile dice. - Joe White
how many D&D players here ? :) - Stefano Borini
Knuth spent years figuring out the number. - Nosredna

8 Answers

12
votes

80% of all statistics are made up on the spot, including this one.

I think you'll find that Jon Skeet has the right idea.

9
votes

I don't believe it was meant to be taken as an exact number at all. Just "almost all the time."

6
votes

I don't believe it was supposed to be taken literally. There are some circumstances and environments in which optimization is paramount (and hence the 97% rather than say, 99%), but for the majority of programmers, writing the majority of software, the majority of the time - optimization should occur only when necessary, and after proper profiling.

4
votes

In answer to this part of the question:

This sentence is written in a research paper, how come a subjective statement get accepted in such formal document?

Research gets published if it satisfies the norms for what is "research" in the relevant discipline. So for example:

  • Experimental Physics and Chemistry requires reproducible results. If the results are not reproducible it is a black mark against the researcher.

  • Medicine requires studies with a statistically significant findings. Double-blind studies with a large sample size are ideal, but such studies are often too expensive, or not possible for ethical reasons.

  • Mathematicians require proofs. And you'd better not slip up.

  • Philosophers like a good argument ... 'nuf said about them I think.

With the possible exception of Mathematics, there is going to be a degree of subjectivity in virtually all research papers. But this does not necessarily make them bad. Subjective statements per se are only a problem if the reader is liable to misinterpret them as objective.

Papers in the disciplines of Computer Science and Software Engineering are particularly prone to a degree of subjectivity. I think this is inevitable, because in many CS/SE fields it is really hard (expensive) to do the experiments that would allow one to make totally objective statements. For example, how can you measure whether premature optimization (rather than something else) has caused a problem? Or more concretely, how can you objectively measure whether a monolithic kernel is better than a microkernel?

Concerning the quote (I assume) from Knuth:

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

This is subjective, but Knuth is clearly making no pretension of objectivity here. Rather, he is giving some advice in a particularly pithy and memorable way. This is the kind of stuff that makes research papers interesting to read, IMO.

And for the record, Knuth's opinion is shared by 97% of all experienced software developers. (I just made that up :-)

1
votes

I think that statement of Knuth's is mainly a case of "argument by prestige". Who's going to debate it?

I was a prof and, believe me, profs get away with a lot of loose assertions, especially in computer science.

My favorite example of where professors have blinders has to do with software performance, where they go on about big-O and tricky compiler optimization while totally missing the industrial phenomenon of gi-normous software and massive inefficiency due to mountainous over-design.

1
votes

I believe the answer from Mike Dunlavey is the closest one. I believe that Knuth get away with this just because he is 'Knuth'. Imagine someone like me saying that statement in a paper. Well... maybe a lot of people will agree with me, but until it's proven theoretically, my paper will not be accepted.

And people shared Knuth's feeling because they know who is Knuth. Imagine that he doesn't know who Knuth is, I can say that the probability of he rejects that statement will be bigger substantially (Stephen: it won't be 97% anymore ;) )

0
votes

This sentence is written in a research paper, how come a subjective statement get accepted in such formal document?

Because research is not only facts, it's also point of view of recognized authorities, backed or not by facts, but also by gut feelings. Remember that Einstein did not believe in Heisenberg uncertainty principle.

0
votes

Just a rough figure as others have pointed out. It's worth noting that the qoute was from the 70s (1974) in favor of using goto statements to speed up measured, critical paths in software.

The nature of applications was a bit different then. The hardware was so tight and limited, but there weren't say, raytracing products where half the software might consist of trying to trace a hundred billion light rays and invoking shaders with the ultimate goal of speed.

If we imagine something like Adobe Photoshop, maybe at least a quarter of their software would be spent looping through pixels, and any image loop is performance-critical since it can easily loop through millions and millions of pixels (just take the number of pixels our monitors display as a "base" figure). As a result, they might have a quarter or more of their codebase modeling critical paths and genuinely benefiting from micro-level optimizations like multithreading, SIMD, or GPU processing.

The true figures are going to vary wildly by context, but something to watch out for, and what Knuth was trying to express with that figure, is that a premature "optimizer" might very well try to optimize everything, whether or not it's actually critical (and whether or not it actually shows a genuine improvement).