lua-users home
lua-l archive

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

On Fri, Nov 8, 2019 at 10:23 PM Enrico Colombini <> wrote:

> But, if I remember correctly, in both Microsoft and Borland compilers clock() returned a system-wide tick count value, a value that was incremented by the real-time clock interrupt routine (INT 08H)

The clock() function debuted in Microsoft C v5.1 (1988). I can see that its return value changes by either 50 or 60 18-19 times per second, which means it is indeed in sync with the PC timer interrupt and it reports milliseconds.

Its description in the various pieces of documentation is confusing. What it actually does is settled in a KnowledgeBase article:

(begin quote)

Product Version(s): 5.10   |  5.10
Operating System:   MS-DOS |  OS/2
Flags: ENDUSER | S_QuickC S_QuickAsm docsup
Last Modified: 17-JUL-1990    ArticleIdent: Q49729

The clock function is documented as telling how much processor time
has been used by the calling process. This definition is misleading.

The clock function returns a clock_t (long) value, which is the
difference between the time field (for seconds) and millitm field (for
milliseconds) in the structure that is returned from two calls to the
ftime function. The first call to ftime is made within the start-up
code of the executing program, and the second call is made when the
clock function is explicitly called in your code.

This means that the value returned by clock is the number of CLK_TCKs
(milliseconds) elapsed since the start-up code was executed, or -1 if
the function was unsuccessful.

(end quote)

I guess we can say that clock() was working more or less correctly in MS DOS, and already in 1990 Microsoft knew it would not work correctly in a multi-tasking environment such as OS/2 they were developing with IBM, and judging from the confused documentation they could not quite decide (then) how they would like to proceed. At some later point they apparently decided MS DOS compatibility was more important.