#include #include #include #include #include #include #define MAXVAL 1000 #define NCLOCKREADS 100 /* consider adding check on precision of gettimeofday, then check on precision of timers, then check on precision of thread scheduling */ int main () { time_t t0, t1, t2; int count[MAXVAL]; long d, d_sec, d_usec; int i; struct timeval tv1, tv2; struct tms buffer; memset (val, 0, sizeof (val)); if (gettimeofday (&tv1, NULL)) { perror ("gettimeofday"); } t0 = t1 = times(&buffer); do { for (i = 0; i MAXVAL) d = MAXVAL-1; count[(int) d]++; t1 = t2; } if (gettimeofday (&tv2, NULL)) { perror ("gettimeofday"); } d_sec = tv2.tv_sec - tv1.tv_sec; d_usec = tv2.tv_usec - tv1.tv_usec + 1000000*d_sec; } while (d_usec < 1000000); printf ("elapsed time = %ld usec\n", d_usec); printf ("elapsed ticks = %ld\n", (long)(t2-t0)); printf ("ticks per second = %10ld\n", (long)(t2-t0)); printf("ticks frequency\n----- --------\n"); for (i = 0; i < MAXVAL; i++) { if (count[i]) printf ("%5d %5d\n", i, count[i]); } return 0; }