This preview shows page 1. Sign up to view the full content.
Unformatted text preview: igh cycle counts for multiplication are due to an anomaly in our benchmark data. Identifying such anomalies is an important component of performance analysis and optimization. We return to this issue in Section 5.11.1. We will see that we can improve on this performance considerably. 5.4 Eliminating Loop Inefﬁciencies
Observe that procedure combine1, as shown in Figure 5.5, calls function vec_length as the test condition of the for loop. Recall from our discussion of loops that the test condition must be evaluated on every iteration of the loop. On the other hand, the length of the vector does not change as the loop proceeds. We could therefore compute the vector length only once and use this value in our test condition. Figure 5.6 shows a modiﬁed version, called combine2, that calls vec length at the beginning and assigns the result to a local variable length. This local variable is then used in the test condition of the for loop. Surprisingly, this small change has a signiﬁcant effect on program performance. Funct...
View Full Document
- Spring '10
- The American