lua-users home
lua-l archive

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


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

-- Roberto