Re: Another Tricky Problem I am Messing With (Not Homework)
- From: "Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx>
- Date: Wed, 19 Sep 2007 15:47:55 GMT
Keith Thompson <kst-u@xxxxxxx> wrote in message
news:lnd4wfnnb3.fsf@xxxxxxxxxxxxxxxxxx
"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.
Well, I've shed a little light (AND some heat) on this, but
it just seems to fly right over the heads of the "frequent posters"
here...and then they REALLY don't help matters by "snipping"
out the explanation...
But <big sigh, waiting for this to snipped out again>, AS I
SAID IN THE POST YOU ARE RESPONDING TO, you
are missing/misinterpreting a key word in the standard:
"The clock function returns the implementation's best approximation..."
"APPROXIMATION"! SEE IT?!??!!!
"APPROXIMATION"!!! SEE IT!!????!!!?!!
"APPROXIMATION"!!!!!!! SEE IT??!???!!!??!??!!!
Your so-called "requirement" is only an "APPROXIMATION"
by the "IMPLEMENTATION".
In other words, it's whatever the friggin' OS has handily available
to return to the function. THE STANDARD DOES NOT "REQUIRE"
THAT THE OS IMPLEMENT A "PERFORMANCE MONITOR"
(WHICH ARE HIDEOUS PERFORMANCE-DRAINERS) FOR
EVERY FRIGGIN' PROCESS TO SUPPLY WHAT YOU HAVE
ERRONEOUSLY DECIDED IS THE CORRECT "PROCESSOR
TIME".
Does that shed enough light for you?
MY OS apparently just returns something that is effectively
the same as "wall clock" time as ITS "approximation" of "processor
time". If you think that it is a slaggard among OSs for doing so,
you might want to re-read all the stuff I wrote in the post you
responded to, carefully, and look up the confusing "technical
words", and read up on "performance monitors" and ponder
why sys admins rarely run them and get so mad if somebody
else does and eventually have a little light bulb go off over your
head as you get the "clear light" as to how modern high-performance
"multi-tasking" systems actually work...
Then you'll understand perfectly, without even being told, what
the pesky "_sleep" function is doing, and you'll be so "enlightened"
that you'll suddenly "grok" why that "confusing" six-line program
I wrote behaves the way it does (and why there's a good chance
it would behave that way on a LOT of systems).
You'll even understand stuff like why I am only using tiny fraction
of my "processor time" right now as I type this, even with many other
programs running "simultaneously". You'll understand that they are
all effectively mostly a"_sleep", waiting for the OS to return a
user "event" to wake them up again, perhaps to use as much as
50% of "processor time" if I do something really crazy...
And if all that doesn't shed enough light, consider carefully the
apparent contradiction between the "requirement" you believe
the standard imposes, and the footnote that you included in
your own post:
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.
Whaaaa? You mean I can just call clock() at the beginning of
the program (or any time, like I did in my program) and then subtract
subsequent call return values to measure the TIME SPENT (wall
clock time?) "in a program"? Shirley, they must have meant
"processor time" when they wrote "time spent", and were just
a little "sloppy" with their language...but I always sloppy thinking
results inevitably in sloppy writing...
---
William Ernest Reid
.
- Follow-Ups:
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Old Wolf
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Keith Thompson
- Re: Another Tricky Problem I am Messing With (Not Homework)
- References:
- Another Tricky Problem I am Messing With (Not Homework)
- From: joebenjamin
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Miguel Guedes
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Bart van Ingen Schenau
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Mark McIntyre
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Bill Reid
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Mark McIntyre
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Bill Reid
- Re: Another Tricky Problem I am Messing With (Not Homework)
- From: Keith Thompson
- Another Tricky Problem I am Messing With (Not Homework)
- Prev by Date: Re: Ode to Keith
- Next by Date: Re: Hi guys~ i wonder that why this simple code error!!
- Previous by thread: Re: Another Tricky Problem I am Messing With (Not Homework)
- Next by thread: Re: Another Tricky Problem I am Messing With (Not Homework)
- Index(es):
Relevant Pages
|