For short computations or on a lightly loaded machine

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ng the cycles that elapse */ /* while sleeping for sleeptime seconds */ double mhz(int verbose, int sleeptime) { double rate; start_counter(); sleep(sleeptime); rate = get_counter() / (1e6*sleeptime); if (verbose) printf("Processor clock rate ˜= %.1f MHz\n", rate); return rate; } code/perf/clock.c Figure 9.10: mhz: Determines the clock rate of a processor. to 1 shows that it reports a clock rate within 1.0% of the rated performance for the processor. This example clearly shows that our routines measure elapsed time rather than the time used by a particular process. When our program calls sleep, the operating system will not resume the process until the sleep time of one second has expired. The cycles that elapse during that time are spent executing other processes. 9.4.1 The Effects of Context Switching A naive way to measuring the run time of some procedure P is to simply use the cycle counter to time one execution of P, as in the following code: 1 2 3 4 5 6 double time_P() { start_counter(); P(); return...
View Full Document

Ask a homework question - tutors are online