CMPSC 311, Introduction to Systems Programming

Introduction to Unix
Solutions to Exercises



Exercise 3
It's the elapsed time that matters.  You should consider how long we had to wait (wall-clock time) or how much time the processor spent executing the program (CPU time, further subdivided into user time and system time).

Wall clock time is calculated by making two calls to some function like gettimeofday(), and then subtracting.

The clocks themselves are usually pretty good, so we need to look at reproducibility - If you repeat the program, do you get the same time?  There is always a small amount of variation.  More importantly, processes compete with each other for use of the processor, and some other process may have run in addition to the one you are trying to measure.  You could also have two cores, and a program that takes advantage of that, so the wall-clock time on a two-core system is not reproducible on a one-core system.
You're on your own here ...  the last one is either annoying or tricky, depending on whether you look at a function like time() or file formats.  For Excel, see http://support.microsoft.com/kb/q180162/ although that may be more than you wanted to know.



Last revised, 9 Jan. 2012