[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: get time in ms?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 16 Nov 2009 10:10:07 -0200
> 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)
188.8.131.52 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 ;)