This preview shows page 1. Sign up to view the full content.
Unformatted text preview: for the calling functions. 5.15.2 Using a Proﬁler to Guide Optimization
As an example of using a proﬁler to guide program optimization, we created an application that involves several different tasks and data structures. This application reads a text ﬁle, creates a table of unique words and how many times each word occurs, and then sorts the words in descending order of occurrence. As a benchmark, we ran it on a ﬁle consisting of the complete works of William Shakespeare. From this, we determined that Shakespeare wrote a total of 946,596 words, of which 26,946 are unique. The most common word was “the,” occurring 29,801 times. The word “love” occurs 2249 times, while “death” occurs 933. Our program consists of the following parts. We created a series of versions, starting with naive algorithms for the different parts, and then replacing them with more sophisticated ones: 1. Each word is read from the ﬁle and converted to lower case. Our initial version used the functi...
View Full Document
- Spring '10
- The American