[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: get time in ms?
- From: Mark Hamburg <mark@...>
- Date: Mon, 16 Nov 2009 07:34:04 -0800
On Nov 16, 2009, at 4:10 AM, Roberto Ierusalimschy wrote:
>> The POSIX standard specifies os.clock() returning CPU time used. But
>> microsoft POSIX library os.clock() returns wall time elapsed since the
>> process started. You'd better avoid using it when your lua code is
>> supposed to run both on Windows and Linux. We learned this a hard way.
> It is not the POSIX standard that specifies that clock() returns CPU
> time. It is the ISO (ANSI) C standard:
> ISO/IEC 9899:1999 (E)
> 126.96.36.199 The clock function
> The clock function returns the implementation’s best approximation
> to the processor time used by the program since the beginning
> of an implementation-defined era related only to the program
> invocation. To determine the time in seconds, the value returned
> by the clock function should be divided by the value of the macro
> CLOCKS_PER_SEC. If the processor time used is not available or
> its value cannot be represented, the function returns the value
> Windows should follow that standard too. (They say they do.)
> Of course, one can say that wall time is their "best approximation"
> to the processor time ;)
Sigh. At least I don't need to say nice things about Microsoft and Windows any more. ;-)
At this point though the question for Microsoft would probably be: How many things will break if we fix this? After all it works as documented by Microsoft. It's just that their choice isn't standards compliant.