Re: clock()

From: Alexander Grigoriev (alegr_at_earthlink.net)
Date: 07/08/04


Date: Thu, 8 Jul 2004 13:16:53 -0700

The standard says:

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).266)

Footnote 266:
266) In order to measure the time spent in a program, the clock function
should be called at the start of
the program and its return value subtracted from the value returned by
subsequent calls.'

Looks like the forwat wording is very ambiguous and clock() function is not
obliged to return 0 at the start of the program. And "Processor time"
meaning is never explained in the standard.

"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:OqiikaPZEHA.2408@tk2msftngp13.phx.gbl...
> Carl Daniel [VC++ MVP] wrote:
> > Victor Bazarov wrote:
> >
> >
> >>I wonder whether Microsoft people know about the 'clock' problem...
> >
> >
> > ... since clock() is apparently behaving exactly the way the MSDN
> > documentation says it behaves, I'd guess that they know about it, yes.
> >
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_clock.asp
> >
> > "Return Value
> >
> > The elapsed wall-clock time since the start of the process (elapsed time
in
> > seconds times CLOCKS_PER_SEC). If the amount of elapsed time is
unavailable,
> > the function returns -1, cast as a clock_t.
> > "
>
> But I've not seen it listed in the Standard [non-]Compliance section.
> IMO it should be. The Standard states that 'clock' should return
> "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." (emphasis mine). It is rather
> apparent that it's not the _best_ approximation, wouldn't you say?
>
> So, my statement should rather have been "I wonder whether Microsoft
> people recognise the 'clock' behaviour as non-standard", which I guess
> they don't because the documentation states "ANSI" in "Compatibility"
> section.
>
> V



Relevant Pages

  • Re: Another Tricky Problem I am Messing With (Not Homework)
    ... just pointed out your and Keith Thompson's ... I don't believe I've misunderstood the C standard, ... The clock function determines the processor time used. ...
    (comp.lang.c)
  • Re: clock() function
    ... > "The clock function returns the implementation’s best approximation to the ... > below) wrap, so storing that in a double won't help, and the period the OP ... Neither the standard nor the previously quoted documentation provide ...
    (comp.lang.c)
  • Re: clock() function
    ... > "The clock function returns the implementation’s best approximation to the ... > only to the program invocation. ... > below) wrap, so storing that in a double won't help, and the period the OP ... Maybe someone else will add more input about the standard. ...
    (comp.lang.c)
  • Re: clock()
    ... > Alexander Grigoriev wrote: ... >> Looks like the forwat wording is very ambiguous and clockfunction is ... >> meaning is never explained in the standard. ... > What precisely do you find ambiguous about the clock function ...
    (microsoft.public.vc.language)
  • Re: time output in milliseconds
    ... >> The clock function returns the implementation's best approximation ... Both start at the same time, as program startup is part of program ... wording like "the best approximation", which can mean anything at all. ... Dan Pop ...
    (comp.lang.c)