Lab – Memory Checker, Timing, Profiling

If this lab has multiple sections, for numbering purposes on your labsheet denote answers from part 1 as 1.1, 1.2, etc., and answers from part 2 as 2.1, 2.2, …

For questions that require an answer, fill in a text file called lab10 and submit it along with any other requested files.

Questions will be denoted with a Q.


Using the time utility

We're going to use time to gather runtime data about our quicksort, on strings.

We will sort inputs of 10,000, 20,000, ... , 100,000 words, and chart our results.

C's clock Command

C has a clock command in its library. Other languages have similar ideas. See sortr.c for an example.

It gives us a little better granularity, about what we're timing (we can skip overhead, etc.). Essentially, there is a clock that starts at 0 when your program starts, and should only tick while your program is executing (as opposed to being sliced out). Each call to clock() just grabs that time. So, you grab a start and end time, take the difference.

clock() returns the # of tics, which is system-dependent, both the value and the granularity. Dividing by CLOCKS_PER_SEC will give you the time, in seconds. But, for graphing/evalution purposes, tics is fine. Don't divide away significant digits.

Using a bit of the gprof utility

For another approach at the same problem, we're going to count the # of swaps performed, rather than measure raw time.

We'll still be working w/the same set of inputs: 10,000, 20,000, ... , 100,000 words, and graph our results.