Re: clock()
From: Alexander Grigoriev (alegr_at_earthlink.net)
Date: 07/08/04
- Next message: Mark: "Get remote env. variable"
- Previous message: Doug Harrison [MVP]: "Re: volatile bool"
- In reply to: Victor Bazarov: "Re: clock()"
- Next in thread: Victor Bazarov: "Re: clock()"
- Reply: Victor Bazarov: "Re: clock()"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Mark: "Get remote env. variable"
- Previous message: Doug Harrison [MVP]: "Re: volatile bool"
- In reply to: Victor Bazarov: "Re: clock()"
- Next in thread: Victor Bazarov: "Re: clock()"
- Reply: Victor Bazarov: "Re: clock()"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|