This preview shows page 1. Sign up to view the full content.
Unformatted text preview: r would recognize that each call to strlen in the loop test will return the same result, and hence the call could be moved out of the loop. This would require a very sophisticated analysis, since strlen checks the elements of the string and these values are changing as lower1 proceeds. The compiler would need to detect that even though the characters within the string are changing, none are being set from nonzero to zero, or vice-versa. Such an analysis is well beyond that attempted by even the most aggressive compilers. Programmers must do such transformations themselves. This example illustrates a common problem in writing programs, in which a seemingly trivial piece of code has a hidden asymptotic inefﬁciency. One would not expect a lower-case conversion routine to be a limiting factor in a program’s performance. Typically, programs are tested and analyzed on small data sets, for which the performance of lower1 is adequate. When the program is ultimately deployed, however, it is 214 CHAPTER 5. OPTIMIZING PROG...
View Full Document
- Spring '10
- The American