Re: Another Tricky Problem I am Messing With (Not Homework)



"Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx> writes:
[...]
Ah yes, the non-sequitur vulgar life strategy tactic. I NEVER
asked for any help here, just pointed out your and Keith Thompson's
errors of understanding the "C" standard and computer science
after the 1970s...
[...]

I don't believe I've misunderstood the C standard, but I never quite
understood what the program you posted is doing, partly because it
used some non-standard function called "_sleep".

Here's what the standard says about the clock() function
(C99 7.23.2.1):

Synopsis

#include <time.h>
clock_t clock(void);

Description

The clock function determines the processor time used.

Returns

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

with a footnote:

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.

Now the behavior you described for the program you posted *seemed* to
be inconsistent with that. Either something odd is going on on your
system (e.g., your program uses CPU time even during the _sleep()
calls), or your implementation's clock() function isn't working
properly ("properly" meaning consistently with the standard's
requirements), or something else is going on.

Perhaps you can shed some light on this.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Another Tricky Problem I am Messing With (Not Homework)
    ... I don't believe I've misunderstood the C standard, ... "The clock function returns the implementation's best approximation..." ... Yes, the standard only requires an "approximation", but did you miss ... seconds of processor time while it was sleeping for 4 seconds and not ...
    (comp.lang.c)
  • Re: Another Tricky Problem I am Messing With (Not Homework)
    ... Keith Thompson wrote in message ... 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: speed of execution
    ... pete wrote: ... The clock function in is for timing programs ... The clock function determines the processor time used. ...
    (comp.lang.c)
  • Re: get the time needed to process one function.
    ... I see no reason. ... The clock function determines the processor time used. ... only to the program invocation. ...
    (comp.lang.c)