|
|
8.2 What to Optimize
We want to optimize things that happen frequently. There are two kinds of frequently: (1) how frequently a piece of code is ever written and (2) how frequently a piece of code is executed within a program.
For (1), Knuth (1971) shows empirically that simple assignment statements with one operation and one to three variables are themost often used statements:
A := B
A := A OP 1
A := A OP k
A := B OP k
A := B OP C
Here, A, B, and, C are variables and k is a constant. Follow-up studies have continued to comfirm this. It does little good to optimize for things programmers rarely write.
For (2), code in loops tends to be executed the most; thus optimizations concentrate onloops.
|