Subject: Can Cygwin's gettimeofday() count to 30us resolution instead of 1 0ms?
From: "Wong, Homer" <[email-masked]>
To: [email-masked]
Cc: "Wong, Homer" <[email-masked]>
Date: Wed, 22 Mar 2000 16:57:43 +1100

Hi

Can Cygwin's gettimeofday() measure down to Linux's 30us (microsecond) timer
resolution instead of Windows' 10 ms (millisecond) timer resolution? I used
the following program to test gettimeofday():

#include <time.h>
#include <stdio.h>
#include <sys/time.h>

int main()
{
        struct timeval tv;

        int i;
        for (i=0; i<1000;i++)
        {
                gettimeofday(&tv, (struct timezone *) 0);
                printf("%lf \n", tv.tv_sec * 1000000.0 + tv.tv_usec );
        }
}

When I compiled it using Cygwin B20.1 on a Pentium II ??? Windows NT box,
the (annotated) output was:

217722273000.000000 (repeated ??? times)
217722283000.000000 (repeated 287 times)
217722293000.000000 (repeated 287 times)
217722303000.000000 (repeated 287 times)
217722313000.000000 (repeated ??? times)

Basically, it was only measuring at 273ms, 283ms, 293ms i.e. about every
10ms.

When I compiled it using gcc-2.7.2.1-2 on a Pentium II ??? Red Hat Linux 4.2
box, I got 1000 uniq time values e.g.:
953703420374555.000000 
953703420374954.000000 
953703420374986.000000 
953703420375010.000000 
953703420375032.000000 
953703420375055.000000 
<etc>

This was much better, measuring at 374.555ms, 374.954ms, 374.986ms,
375.010ms i.e. about every 30us.

The Linux code for gettimeofday() is in
/usr/src/linux/arch/i386/kernel/time.c or
http://src.openresources.com/linux-2.2.1/S/arch%20i386%20kernel%20time.c.htm
l#250 or http://src.openresources.com/linux-2.2.1/D/do_gettimeofday.html.

Homer Wong,
Telstra, Australia
[email-masked]

--
Want to unsubscribe from this list?
Send a message to [email-masked]