www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/10/17/22:10:11

Xref: news-dnh.mv.net comp.os.msdos.djgpp:2719
Newsgroups: comp.os.msdos.djgpp
Path: news-dnh.mv.net!mv!news.sprintlink.net!EU.net!sun4nl!phcoms4.seri.philips.nl!newssvr!kunst
From: kunst AT natlab DOT research DOT philips DOT com (Pieter Kunst)
Subject: Re: clock() unit ?
Sender: news AT natlab DOT research DOT philips DOT com (USENET News System)
Organization: Philips Research Laboratories, Eindhoven, The Netherlands
References: <45vkr2$2l4 AT news DOT cea DOT fr>
Date: Tue, 17 Oct 1995 15:12:29 GMT
Lines: 58
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

Eric Nicolas (nicolas AT dsys DOT ceng DOT cea DOT fr) wrote:

> ANSI C tell that there should be a CLK_TCK constant 
> which says that, but I found somewhere in djgpp .H 
> a #define CLK_TCK 100, and when trying that it is
> obvious that this is wrong.
> 
> In fact, it seems that there are about 1 million 
> clock() units per seconds. But what is the real value ?

and:

> There have been many different answers to my initial question (what is the
> real clock() unit, and which constant to use to translate from clock() units
> to seconds) thanks.
>
> But, I think the problem is not to be consistent with such or such ANSI
> or POSIX specs. For a compiler like GNU wich is often used in replacement of
> other commercial compilers, I think it is a goal to be compatible with ALL
> the rules (ANSI, POSIX...).
>
> So, in our example, it would be great in DJGPP v2 to have declarations of
> _ALL_ the constants :
>	CLK_TCK
>	CLOCKS_PER_SEC
>	... others constants
> and to have them _ALL_ equal to the same value.
>
> So, the source code with clock() coming from another compiler will run
> correctly once compiled with djgpp.
>
> I'm waiting for reactions to this proposition. 
> I hope dj delorie will hear of it.

Some remarks:

(1) ANSI C defines a constant CLOCKS_PER_SEC. You should use this value
    to obtain the amount of CPU time used since the first call to clock()
    in *seconds*, i.e. clock()/CLOCKS_PER_SEC.
    This will make your program behave similar when compiled with other
    ANSI C conforming compilers.

(2) CLK_TCK is used on *some* platforms (including our HP-UX machine)
    to indicate the clock resolution. Example: on our HP-UX 700 machine
    the (default) clock resolution is 10 milliseconds, and in <limits.h>
    the following line is present:

      #define CLK_TCK  100    /* Number of clock ticks per second */

  /*******************************************************************/
    However, this value is to be used not with clock(), but with the
    times() (=get process and child process times) (POSIX) function.
    (Try 'man times' on your Unix machine...)
  /*******************************************************************/


Pieter Kunst (kunst AT natlab DOT research DOT philips DOT com)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019