Assignment 4
CS 265/571 Advanced Programming Tools and Techniques
Instructors: Jeremy Johnson and Kurt Schmidt
Due date: Fri. Mar. 11 at 11:55 pm
Introduction
The purpose of this assignment is for students to learn how to empirically
analyze the runtime of a program and to relate this to the theoretical runtime.
Students will also learn how to profile and time programs and to use this information
to determine whether to optimize a program and if so what to optimize.
Students should review and think about the material in
Lecture 8
(chapter 7 of the text).
In particular, you will need to use the unix time command, the clock function,
and the profiler gprof.
- Time the C and C++ versions of the markov program on the
psalms
input using the unix time command. You should redirect output to /dev/null.
How do they compare? How do the times compare to what is given in the
book? What conclusions can you draw.
- Profile, using gprof, the C and C++ version of the Markov program.
Summarize your findings.
- Write a main program to time n inserts to the STL map (for
different values of n). You should use a map whose index is a string
and whose value is an int. You can use strings that are the ascii
version of numbers. I.e. you can count from 1 to n and convert each
integer to a string and use converted string to index into the map. This way
you can easily generate as many strings as you need without reading from
a file.
Use the function clock() to measure the times
as was shown in the sample programs (sorti and sortr) to obtain times
for different numbers of insertions. You may need to insert a large
number of words so that the insertions into map take time larger than
the resolution of clock. Plot the times and compute the
ratio of the times to n, nlog(n), n^2. What can you say about the
growth rate? Can you guess the data structure that is used to implement
the map?
What to hand in
Place your solution in a directory called A4. Your directory
should contain a file called README that describes all of the files
in A4 and summarizes what you did. Make sure to indicate if any
of the problems were not done or are not working.
Include the following:
- README - description of what you did (include the machine name and
type with CPU speed, amount of memory, and operating system) and your
conclusions.
- times - a file containing the output of the time command from timing
the C and C++ versions of the Markov program running with psalms.txt as
input. In addition to the times, you should briefly summarize your results.
- markov_C.prof - a file containing the output of gprof from running the
C version of the Markov program on psalms.txt. Simply redirect the output
of gprof to the file.
- markov_Cpp.prof - a file containing the output of gprof from running the
C++ version of the Markov program on psalms.txt. Simply redirect the output
of gprof to the file.
- prof - a file containing your summary of the two profiles of the C and
C++ Markov programs.
- timemap.cpp - C++ source file for the timing insertions into map.
- maptimes - a file containing pairs (separated by spaces -
one pair per line) of input sizes (number of insertions) and times.
- maptimes.{jpg,ps,eps} plot of the times in maptimes.
- maptimes.summary - your observations and conclusions regarding the
times for map.
Create a gzipped tar file containing a directory called A4 (use
the command tar to do this) with your solutions. If
you created a directory called A4 with all of the files for your
assignment 2 solution, you can use the command:
$ tar -zcvf A4.tar.gz A4
to create the desired gzipped tar file (the convention is to use the .tar
extension for tar files and the .gz extension for gzipped files). See
man tar of info tar for more information about tar.
All assignments should be submitted using webct. You should submit your
gzipped tar file.