4 ms·
Another quote from Knuth, from that same paper: > The improvement in speed from Example 2 to Example 2a is only about 12%, and many people would pronounce that
by gnuvince 4y ago
Another quote from Knuth, from that same paper:
> The improvement in speed from Example 2 to Example 2a is only about 12%, and many people would pronounce that insignificant. The conventional wisdom shared by many of today's software engineers calls for ignoring efficiency in the small; but I believe this is simply an overreaction to the abuses they see being practiced by penny-wise-and-pound-foolish programmers, who can't debug or maintain their "optimized" programs. In established engineering disciplines a 12% improvement, easily obtained, is never considered marginal; and I believe the same viewpoint should prevail in software engineering. Of course I wouldn't bother making such optimizations on a one-shot job, but when it's a question of preparing quality programs, I don't want to restrict myself to tools that deny me such efficiencies.
That paper was published in 1974 and yet it captures the mindset of many a programmer in 2023 perfectly. The part I like about this paragraph is the "easily obtained" sentence; I saw a comment from someone mentioning that they made a JavaScript program 10 times faster by replacing the common functional programming combinators (map, filter, reduce, etc.) with for loops. I think most of us would say such a change is easily obtained, does not make the code impossible to debug or maintain, and gives such a massive improvement that it should be a no brainer to reach for it.
- cranium 4y agoGood point, and also why the topic of performance is so prone to heated discussions. To paraphrase Knuth "97% of the time, don't optimize except if it's an easy 12% improvement". I don't think there exists a good heuristic that works each time or for all languages. The right decision is left (pun intended) to the programmer that has to live with it. For me the ideal decision took into account the performance tradeoffs of each level of abstraction and chose the "appropriate" one. Obviously, the "appropriate one" depends on an uncountable number of variables including future scaling issues, probability of refactoring/irrelevance, cost/reward of spending the time to optimize the function, ...