This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strange bug in gettimeofday function


Andrew Makhorin wrote:
Hi,

I detected a strange bug in the standard function gettimeofday.
It *sometimes* reports the time which being expressed as the integer
number of milliseconds is *less* than the time obtained *earlier* with
the same function.

If you mean that you call gettimeofday twice and you get different values at each call, with a difference of about 100 ms, then this is all right. Read on...




The expression 1000000 * tv.tv_sec + tv.tv_usec is calculated in 64-bit arithmetic, so overflow cannot happen. The negative difference in the time values on two successive calls is about 100 milliseconds.

Please keep in mind that windows is a pre-emptive multi-tasking OS. This means that there is a lot of time-sharing among multiple processes.


Windows could be accurate up to 15 ms or perhaps a little bit more. However, it is very difficult to achieve less than 15 ms or microsecond accuracy with windows due to the limitation on the OS itself. Our extensive tests on windows clocks and timers reveal that windows cannot be accurate to the microsecond level or below 15 ms.

FWIW, The accuracy of gettimeofday may also depend on the processor speed.

In any case, in my experience, windows cannot be accurate with a precision of up to 15 milliseconds.

The time difference you are seeing seems normal to me (unless I have not understood you correctly, in which case, I apologize in advance.)

Thank you very much.


Best Regards,


Carlo


-- Carlo Florendo Softare Engineer/Network Co-Administrator Astra Philippines Inc. UP-Ayala Technopark, Diliman 1101, Quezon City Philippines http://www.astra.ph

Member of the Astra Group of Companies
5-3-11 Sekido, Tama City
Tokyo 206-0011, Japan
http://www.astra.co.jp

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]