lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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.
>> http://msdn.microsoft.com/en-us/library/4e2ess30%28VS.80%29.aspx
> 
> 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)
>  7.23.2.1 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
>    (clock_t)(-1).
> 
> 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.

Mark