calibrating time
Castl Troy
mastah at phreaker.net
Tue Dec 21 11:16:04 PST 2004
Hello hackers,
Just want to ask people here who have time to run my program and answer me
back output from it.
Thanks!
=====
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
int main(int argc, char **argv)
{
u_int i, avg, totaldiff = 0;
u_int diff[10];
struct timeval pold, pcur;
fprintf(stderr, "Examining sleep()\n");
for(i=0; i<10; i++) {
gettimeofday(&pold, NULL);
sleep(1);
gettimeofday(&pcur, NULL);
fprintf(stderr, "Pass %2d [ diff: %3lu.%-6lu second(s) ]\n", i,
pcur.tv_sec - pold.tv_sec,
pcur.tv_usec - pold.tv_usec);
diff[i] = pcur.tv_usec - pold.tv_usec;
}
for(i=0; i<10; i++)
totaldiff+=diff[i];
avg = totaldiff / 10;
fprintf(stderr, " -- average diff: %5u microsecond(s)\n", avg);
fprintf(stderr, "\nExamining usleep()\n");
for(i=1;i<11; i++) {
gettimeofday(&pold, NULL);
usleep(1 * 1000 * 1000);
gettimeofday(&pcur, NULL);
fprintf(stderr, "Pass %2d [ diff: %3lu.%-6lu second(s) ]\n", i,
pcur.tv_sec - pold.tv_sec,
pcur.tv_usec - pold.tv_usec);
diff[i] = pcur.tv_usec - pold.tv_usec;
}
for(i=0; i<10; i++)
totaldiff+=diff[i];
avg = totaldiff / 10;
fprintf(stderr, " -- average diff: %5u microsecond(s)\n", avg);
exit(0);
}
More information about the freebsd-hackers
mailing list