Date: Tue, 21 Dec 2004 22:15:33 +0300 From: Castl Troy <mastah@phreaker.net> To: hackers@freebsd.org Subject: calibrating time Message-ID: <6.2.0.7.1.20041221221529.021bb7d0@pop.phreaker.net>
next in thread | raw e-mail | index | archive | help
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);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6.2.0.7.1.20041221221529.021bb7d0>
