calibrating time

From: Castl Troy (mastah_at_phreaker.net)
Date: 12/21/04

  • Next message: Thordur Ivar B.: "Re: calibrating time"
    Date: Tue, 21 Dec 2004 22:15:33 +0300
    To: hackers@freebsd.org
    
    

    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);
    }

    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Thordur Ivar B.: "Re: calibrating time"