Is pre-optimization the root of all evil?







This article is a reaction to another article Performance comes first . Yes, on the Internet again someone is wrong. However, I want to go somewhat beyond the scope of the topic under discussion in order to supplement and deepen the consideration of important aspects.







Knuth's original article



Of course, Knut doesn't need someone to protect him. Indeed, who is Knut and who am I? However, my goal is not to protect Knut, but to protect common sense.







It turns out that the context of the article is very important. Therefore, I will provide a link so that the reader can independently familiarize himself with the original article: http://cowboyprogramming.com/files/p261-knuth.pdf







So, we have before us an article from 1974 by Stanford University entitled β€œStructured Programming with the GOTO Statement” (hereinafter, the author's translation). I wasn’t there yet, but the article was already there. I suspect, as do many of you reading this article.







, , GOTO. . 1974. , : GOTO .







, , GOTO . GOTO , β€” .







:







2.







A[m+1] := x; i := 1;
while A[i] != x do i := i + 1;
if i > m then m := i; B[i] := 1;
else B[i] := B[i] + 1 fi;
      
      





2a.







A[m+1] := x; i := 1; go to test;
loop:  i := i + 2;
test:  if A[i] = x then go to found fi;
       if A[i+1] != x then go to loop fi;
       i := i + 1;
found: if i > m then m := i; B[i] := 1;
       else B[i] := B[i] + 1 fi;
      
      





2 12%, .. . .







. . .

, . : ?







:







There is no doubt that the grail of efficiency leads to abuse. Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.



, . , , . , , 97% : β€” .

.. β€” , . , , :







  1. , .
  2. : .
  3. , .


, . , . , . , . , .







, . , , - . , , . β€” , .







β€œ ?”



, . , , : ?







, β€” . , , . : . , . . , . .







: ?







: ! , , .







, .









. , ? : . , ( ) . , , , .







, , . , , : , , , .. , , , :







  1. ? ?
  2. ? ? ?
  3. ? /.
  4. ?
  5. ?
  6. ..


β€” : β€œ ?”.







. . , .







, -, , , . , PHP/Python, . , .









, , , .







, : β€” .







? ? - , . , . , . , .. .







. , , , , , .., . . . .









. β€” , .







, : β€” . , , .







? . . , , , , , , . , , .







: . .







.








All Articles