Thus operating systems use much more sophisticated

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: e time in seconds rather than clock cycles. 9.5. TIME-OF-DAY MEASUREMENTS 477 code/perf/tod.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include <sys/time.h> #include <unistd.h> static struct timeval tstart; /* Record current time */ void start_timer() { gettimeofday(&tstart, NULL); } /* Get number of seconds since last call to start_timer */ double get_timer() { struct timeval tfinish; long sec, usec; gettimeofday(&tfinish, NULL); sec = tfinish.tv_sec - tstart.tv_sec; usec = tfinish.tv_usec - tstart.tv_usec; return sec + 1e-6*usec; } code/perf/tod.c Figure 9.20: Timing Procedures Using Unix Time of Day Clock. This code is very portable, but its accuracy depends on how the clock is implemented. System Pentium II, Windows-NT Compaq Alpha Pentium III Linux Sun UltraSparc Resolution ( s) 10,000 977 1 2 Latency ( s) 5.4 0.9 0.9 1.1 Figure 9.21: Characteristics of gettimeofday Implementations. Some implementations use interval counting, while others use cycle timers. This greatly affects the measurement precision. 478 CHAPTER...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online