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




Mark McIntyre <markmcintyre@xxxxxxxxxxx> wrote in message
news:vpoge3tpl3u7m2ueaqgnims811jpa63r6b@xxxxxxxxxx
On Wed, 12 Sep 2007 04:58:42 GMT, in comp.lang.c , "Bill Reid"
<hormelfree@xxxxxxxxxxxxxxxx> wrote:

The clock function returns the implementation's best approximation
to the processor time used by the program

Well, yeah, it's supposed to tell you how long the program has
been running.

No, its supposed to tell you the processor time used. Which is
entirely different to wallclock time.

Well, if the program is suspended, it's not using processor time,
and it's not "running", now is it?

I assume you're not used to multitasking operating systems.

Actually, it might be more true that I've forgotten more
about multi-tasking, multi-user, multi-processor systems
than you'll ever know...

On my system the program running time is counted
in milliseconds starting from zero as soon as the program starts.

However this isn't what clock() measures.

No, it's what it returns!

I have no idea how your '_sleep' function works. I suspect that
either '_sleep' delays for a specified interval of CPU time,

No possibility it just delays execution of the program for a
specified amount of time regardless of the "CPU time"?

Its possible, but since its a nonstandard function, we can't say.

We can't even make an educated "guess"? Come on, what
would one of my forays into this group be without some completely
unfounded leap of non-logic?

Since it is nominally a "multi-tasking" single-processor system it
must be sharing that CPU time with all the other programs I'm running,
but that doesn't seem to affect the perceived time as the program
runs or timings returned by clock() much.

My guess:

Thanks for that! My faith in this group has been restored!
Occasionally, it is shaken by somebody who actually responds
based on knowledge, fact, and practical application of
technology to solve real-world problems quickly, but you've
redeemed it!

when you're running this process, it takes 100% of hte CPU
available for the duration of hte "busy wait" loop.

Now let's just think about this for a second...you "guess" that
the "sleep" function bumps the CPU usage of the process up to
100% for the duration of the "sleep" on a "multi-tasking" system
(the exact kind of system you are an "expert" on!).

And yet, it seems to ignorant me that a "multi-tasking" single
processor system must always be stopping execution of processes
to allow other processes to get their share of "CPU time", to
create this "illusion" that they are all "running" at the same time.

But I guess what really happens is that the OS sees a new
process that needs to run when another process is running,
so it bumps the "CPU usage" of the currently running process
to "100%" to allow the new process to run! Brilliant! In fact,
I "guess" you "think" that ALL "simultaneously" running programs
are always using "100%" of CPU time, because how else could
a "multi-tasking" system work?!?!!

Try running a huge
numerical simulation at the same time, say BOINC or converting a nice
big AVI into MPG.

You snipped out (classic behavior) my description of what I did,
as well as the program itself (no need to confuse anybody with the
facts, let's just "guess"). I downloaded about a meg of data from
the net while at the same time started a graphics program that
opened up a thumbnail view of hundreds of JPEGs in a directory,
AND simultaneously ran my friggin' little like six-line program, that
you "guess" was mostly in a "busy/wait state" (whatever the hell that is)
for 10 seconds, and "guess" what? I reported what ACTUALLY
happened, and you snipped it!

Yeah, sure, I could run ever more computationally-intensive
programs; in fact, I run a HUGE numerical simulation every night
that takes everything my poor little computer has to offer and
with nothing else running it still takes HOURS for it to complete
(a few months ago one of your "peers" amusingly sneered at me
that I just wasn't used to writing large-scale programs to support
their "guess" on a subject).

"Guess" what, I'm not going to waste my time running anything
else when I'm running that, because as I've tried to stress repeatedly,
I don't make money by writing programs that DON'T work; in
other words, I'm NOT a "professional" programmer.

I do know this: the documentation for any and all "sleep" functions
of ANY sort is always careful to say that the specified "sleep" time
is the guaranteed MINIMUM amount of time the process will
"sleep". In other words, when it comes time to "wake up", if
there is a gigantic process running, it might take a few milliseconds
to get the "sleeping" process back into the mix...

Either you will see a difference, or your
background jobs will all freeze, or your clock() is nonstandard and
you need a new compiler.

Aside from your rampant "guessing", you keep conflating "sleep"
with "clock()" (though I suspect they may be somewhat tied together
technically at the "implementation"), and any multi-tasking "CPU usage"
with "100%" of all the cycles all the time. My "background jobs" are
not going to "freeze", I was watching several performance monitors
(more processes!) as well as the on-screen progress of my programs
when I ran them before using "sleep". Nothing "froze", and people
who actually know how "multi-tasking" works (and perhaps more
importantly, WHY it works) know why...

As far as my clock() being "non-standard", I say GREAT! Since
it worked for that little test purpose, I'm HAPPY it's "non-standard"!
I guess I can use it if I wanted to "clock" the running time of my
programs, including the "sleep" times (not that I have a lot of use
for that, but something to keep in mind).

Once again, I can only make money if my programs actually WORK,
because again I AM NOT A PROFESSIONAL PROGRAMMER.

Note that clock_t could be signed, unsigned, or floating-point, and
CLK_TCK isn't defined in standard C; the correct macro is
CLOCKS_PER_SEC.

Yeah, I noticed that, but for this development package, they
use a different name for the same macro,

It can't be the same macro if it has a different name....

Yup, spoken like a true "professional"...

---
William Ernest Reid



.



Relevant Pages

  • how can I get the CPU time of a process?
    ... I'm interested in a user command and in a C-function. ... How can I track the number of overflows, without regularly calling clock()? ... CPU time of the process from the beginning, ...
    (comp.unix.misc)
  • Re: Need help with ICETOOL Time masks please
    ... CPU TIME fields to display. ... counter where the bit positions of the clock are numbered 0 to 63. ... CONVERT AS BINARY INT TO DECIMAL ...
    (bit.listserv.ibm-main)
  • Re: OT : Save Windows XP
    ... for a accounting system. ... Yeah, at Y2K a lot of these systems designed when space and CPU ... A minute of CPU time was worth more than 2 hours of mine. ... to do some work and got a call from data management not to do it ...
    (rec.boats)
  • Re: time output in milliseconds
    ... That time period could be a fixed date ... >> the clock() function could return the same value. ... >That typically means that clock returns an estimate of the CPU time ... >would be conforming. ...
    (comp.lang.c)
  • Re: to find execution time
    ... >> cah you please tell me how to find the execution time of a program in c. ... >Call clock() at the start of your program; call clockat the end of ... Note that you get the CPU time used by the program this way. ... Dan Pop ...
    (comp.lang.c)