473,395 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Another Tricky Problem I am Messing With (Not Homework)

This is a problem I was trying to help a few friends figure out for fun. I
am not sure how to go about this, but there is something I am missing
here. Here is what we want the output to be:
Need to read in a time period from the keyboard (for example 1.2 seconds,
3.4 seconds, or 8.37 seconds). Once the time has been read in, we want to
print out the word “TICK” and then wait the designated time period and
print the word “TICK” again. Repeat until there are 6 “TICK”s on the
screen. It would be real neat if we knew how to variate between TICK and
TOCK, however this might be the output.

Enter a time ==2.27
TICK <wait 2.27 seconds>
TICK <wait 2.27 seconds>
TICK <wait 2.27 seconds>
TICK <wait 2.27 seconds>
TICK <wait 2.27 seconds>

Here is what I started, I am lost because I am a newbie lol... This is
wrong any ideas?

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <time.h>
  4.  
  5. int main( )
  6.  
  7. {
  8. clock_t start, end;
  9. float   total_time;
  10.  
  11.  
  12. int i;
  13. int j;
  14. int k;
  15. int timer;
  16.  
  17. printf("Enter any time in seconds\n ");
  18. scanf ("%i", &timer);
  19. getchar ();
  20.  
  21. printf( "Start timing\n" );
  22. start = clock();
  23.  
  24.  
  25. for ( i=0; i<5000; i++ )
  26. for ( j=0; j<1000; j++ )
  27. for ( k=0; k<100; k++ );
  28.  
  29.  
  30. end = clock();
  31.  
  32. total_time = ( end - start ) / CLK_TCK;
  33. printf("TICK\n");
  34. printf("TICK\n");
  35. printf("TICK\n");
  36. printf("TICK\n");
  37. printf("TICK\n");
  38. printf("TICK\n");
  39. printf( "\nTotal Time Elapsed : %0.3f seconds\n", total_time );
  40.  
  41. getch();
  42. }
  43.  

--
Message posted using http://www.talkaboutprogramming.com/group/comp.lang.c/
More information at http://www.talkaboutprogramming.com/faq.html

Sep 10 '07 #1
17 1840
joebenjamin wrote:
This is a problem I was trying to help a few friends figure out for fun. I
am not sure how to go about this, but there is something I am missing
here. Here is what we want the output to be:
Need to read in a time period from the keyboard (for example 1.2 seconds,
3.4 seconds, or 8.37 seconds). Once the time has been read in, we want to
print out the word “TICK” and then wait the designated time period and
print the word “TICK” again. Repeat until there are 6 “TICK”s on the
screen. It would be real neat if we knew how to variate between TICK and
TOCK, however this might be the output.
Had nothing to do so I decided to give it a shot... :)

Made the code as simpler as I could; hopefully you'll understand what the code
does, as I find it self-explanatory.

It's been awhile since I've coded in C (since the late 80's) and am not sure
whether I've used any non-standard C features. Hopefully some of the regulars
here can spot'em and correct'em if I have.

#include <stdio.h>
#include <conio.h>
#include <time.h>

int main( )
{
clock_t start, target, end;
float timer;
int i, j;
char msg[][5] = {"TICK", "TOCK"};
do
{
printf("\nEnter any time in seconds: ");
scanf ("%f", &timer);

i = j = 0;

printf( "Start timing\n" );
start = clock();
while(i++ < 6)
{
target = clock() + (clock_t)(timer*(float)CLOCKS_PER_SEC);

while(clock() < target);

printf("%s ", msg[j]);

if(++j 1)
j = 0;
}
end = clock() - start;

printf( "\nTotal Time Elapsed : %0.3f seconds, %0.3f/iteration\n",
(float)end/1000, (float)end/((i-1)*1000));

printf("Another go? y/[n] ");
} while(getch() == 'y');
}
Sep 10 '07 #2
Miguel Guedes wrote:

<snip>
{
target = clock() + (clock_t)(timer*(float)CLOCKS_PER_SEC);

while(clock() < target);
Although this is a standard conforming way to wait for a certain time
period, it is actually not a very friendly way on a multi-user system.
This loop probably consumes 100% CPU time while it is doing nothing.

For this kind of task, it is advisable to look for a implementation
specific method. Functions like Sleep (Windows) and sleep/usleep (unix)
come to mind.

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
Sep 10 '07 #3
Bart van Ingen Schenau <ba**@ingen.ddns.infowrites:
Miguel Guedes wrote:
<snip>
>{
target = clock() + (clock_t)(timer*(float)CLOCKS_PER_SEC);

while(clock() < target);

Although this is a standard conforming way to wait for a certain time
period, it is actually not a very friendly way on a multi-user system.
This loop probably consumes 100% CPU time while it is doing nothing.
And it doesn't necessarily do what you want it to do. The clock()
function returns an indication of CPU time, not real time. So if, for
example, your program is getting 25% of the CPU, the loop will wait 4
times as long as you probably want it to (while wasting 25% of the CPU
doing nothing particularly useful).
For this kind of task, it is advisable to look for a implementation
specific method. Functions like Sleep (Windows) and sleep/usleep (unix)
come to mind.
Indeed. Delaying for a specified time interval is one of those things
that cannot be done well using only standard C, but that can probably
be done *very* well using some system-specific interface.

(It would have been easy enough for the standard to define a sleep()
function, but applications that need that functionality almost always
need other functionality that can't be define so easily in a portable
interface.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Sep 10 '07 #4
Keith wrote:
) Indeed. Delaying for a specified time interval is one of those things
) that cannot be done well using only standard C, but that can probably
) be done *very* well using some system-specific interface.

A good bet would probably be the POSIX standard.
select(), for example, can be used to sleep for a specified time interval.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Sep 11 '07 #5

Keith Thompson <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Bart van Ingen Schenau <ba**@ingen.ddns.infowrites:
Miguel Guedes wrote:
<snip>
{
target = clock() + (clock_t)(timer*(float)CLOCKS_PER_SEC);

while(clock() < target);
Although this is a standard conforming way to wait for a certain time
period, it is actually not a very friendly way on a multi-user system.
This loop probably consumes 100% CPU time while it is doing nothing.

And it doesn't necessarily do what you want it to do. The clock()
function returns an indication of CPU time, not real time.
Really? Seems to work to a few thousandths of a second
here (note that _sleep() is my development package version of
a sleep/wait/delay function for Windows, and CLK_TCK
is the macro for determining the number of seconds from
clock()):

#include <stdio.h /* required to breathe */
#include <time.h /* required for clock functions */
#include <dos.h /* required for "sleep" function */

int main(void) {
int inc;
clock_t start,end;

for(inc=1;inc<5;inc++) {
printf("Sleeping for %d seconds\n",inc);
start=clock();
_sleep(inc);
end=clock();
printf("Slept for %f seconds\n",((end-start)/CLK_TCK));
}
}

Sleeping for 1 seconds
Slept for 1.000000 seconds
Sleeping for 2 seconds
Slept for 2.000000 seconds
Sleeping for 3 seconds
Slept for 3.000000 seconds
Sleeping for 4 seconds
Slept for 4.000000 seconds

Hey, that appears to be "perfect timing"! Before when I ran
this some of the clock() timings were off by about 0.0002 to
0.0005 seconds; maybe clock() IS dependant on CPU usage...

As usual, I'm confused...
So if, for
example, your program is getting 25% of the CPU, the loop will wait 4
times as long as you probably want it to (while wasting 25% of the CPU
doing nothing particularly useful).
Actually, I would have just thought that you'd be kinda chasing
your CPU cycles around each other and wind up with a mess, as
was previously mentioned...
For this kind of task, it is advisable to look for a implementation
specific method. Functions like Sleep (Windows) and sleep/usleep (unix)
come to mind.
Yes, I think just about all compilers for general purpose computers
allow you to call in some way a system timer for suspending your program
for a period of time...
Indeed. Delaying for a specified time interval is one of those things
that cannot be done well using only standard C, but that can probably
be done *very* well using some system-specific interface.
Yes, since some type of timer and process suspension/activation is
needed for most general purpose computer OSs...
(It would have been easy enough for the standard to define a sleep()
function, but applications that need that functionality almost always
need other functionality that can't be define so easily in a portable
interface.)
Portable to what? Embedded systems again? I'm surprised they
stooped so low as to include something to print to a "screen"...

---
William Ernest Reid

Sep 12 '07 #6
"Bill Reid" <ho********@happyhealthy.netwrites:
Keith Thompson <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>Bart van Ingen Schenau <ba**@ingen.ddns.infowrites:
Miguel Guedes wrote:
<snip>
{
target = clock() + (clock_t)(timer*(float)CLOCKS_PER_SEC);

while(clock() < target);

Although this is a standard conforming way to wait for a certain time
period, it is actually not a very friendly way on a multi-user system.
This loop probably consumes 100% CPU time while it is doing nothing.

And it doesn't necessarily do what you want it to do. The clock()
function returns an indication of CPU time, not real time.

Really?
Yes, really.

C99 7.23.2.1p3:

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

Seems to work to a few thousandths of a second
here (note that _sleep() is my development package version of
a sleep/wait/delay function for Windows, and CLK_TCK
is the macro for determining the number of seconds from
clock()):

#include <stdio.h /* required to breathe */
#include <time.h /* required for clock functions */
#include <dos.h /* required for "sleep" function */

int main(void) {
int inc;
clock_t start,end;

for(inc=1;inc<5;inc++) {
printf("Sleeping for %d seconds\n",inc);
start=clock();
_sleep(inc);
end=clock();
printf("Slept for %f seconds\n",((end-start)/CLK_TCK));
}
}

Sleeping for 1 seconds
Slept for 1.000000 seconds
Sleeping for 2 seconds
Slept for 2.000000 seconds
Sleeping for 3 seconds
Slept for 3.000000 seconds
Sleeping for 4 seconds
Slept for 4.000000 seconds

Hey, that appears to be "perfect timing"! Before when I ran
this some of the clock() timings were off by about 0.0002 to
0.0005 seconds; maybe clock() IS dependant on CPU usage...

As usual, I'm confused...
I have no idea how your '_sleep' function works. I suspect that
either '_sleep' delays for a specified interval of CPU time, or your
program is using exactly 1 second of CPU time per second of real time.
But if _sleep(4) consumes a full 4 seconds of CPU time doing nothing.

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.

[...]

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Sep 12 '07 #7
On 11 set, 23:15, Keith Thompson <ks...@mib.orgwrote:
"Bill Reid" <hormelf...@happyhealthy.netwrites:
Keith Thompson <ks...@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Bart van Ingen Schenau <b...@ingen.ddns.infowrites:
Miguel Guedes wrote:
<snip>
{
target =clock() + (clock_t)(timer*(float)CLOCKS_PER_SEC);
while(clock() < target);
Although this is a standard conforming way to wait for a certain time
period, it is actually not a very friendly way on a multi-user system.
This loop probably consumes 100% CPU time while it is doing nothing.
And it doesn't necessarily do what you want it to do. Theclock()
function returns an indication of CPU time, not real time.
Really?

Yes, really.

C99 7.23.2.1p3:

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 theclockfunction 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).
this mean that if i have a program that count execution's time and run
it several times it should output always the same value? because I
think it should take always the same processor time to run, if it
doesn't have i/o for example

but I tried some code here and even if I use sleep(), what I think
would make the program to doesn't use the processor time, the program
outputs the correct value

Sep 12 '07 #8

Keith Thompson <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
"Bill Reid" <ho********@happyhealthy.netwrites:
Keith Thompson <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Bart van Ingen Schenau <ba**@ingen.ddns.infowrites:
Miguel Guedes wrote:
<snip>
{
target = clock() + (clock_t)(timer*(float)CLOCKS_PER_SEC);

while(clock() < target);

Although this is a standard conforming way to wait for a certain time
period, it is actually not a very friendly way on a multi-user
system.
This loop probably consumes 100% CPU time while it is doing nothing.

And it doesn't necessarily do what you want it to do. The clock()
function returns an indication of CPU time, not real time.
Really?

Yes, really.

C99 7.23.2.1p3:

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).
Well, yeah, it's supposed to tell you how long the program has
been running. On my system the program running time is counted
in milliseconds starting from zero as soon as the program starts.
On some systems, this timing service is not available, so it returns
-1...

What I was really getting at was your statement that you
snipped:
So if, for
example, your program is getting 25% of the CPU, the loop will wait 4
times as long as you probably want it to (while wasting 25% of the CPU
doing nothing particularly useful).
At the very least, this should depend on the system, and at the worst,
may be conflating two values which aren't related to each other on any
system that supports stuff like clock() and sleep()...
Seems to work to a few thousandths of a second
here (note that _sleep() is my development package version of
a sleep/wait/delay function for Windows, and CLK_TCK
is the macro for determining the number of seconds from
clock()):

#include <stdio.h /* required to breathe */
#include <time.h /* required for clock functions */
#include <dos.h /* required for "sleep" function */

int main(void) {
int inc;
clock_t start,end;

for(inc=1;inc<5;inc++) {
printf("Sleeping for %d seconds\n",inc);
start=clock();
_sleep(inc);
end=clock();
printf("Slept for %f seconds\n",((end-start)/CLK_TCK));
}
}

Sleeping for 1 seconds
Slept for 1.000000 seconds
Sleeping for 2 seconds
Slept for 2.000000 seconds
Sleeping for 3 seconds
Slept for 3.000000 seconds
Sleeping for 4 seconds
Slept for 4.000000 seconds

Hey, that appears to be "perfect timing"! Before when I ran
this some of the clock() timings were off by about 0.0002 to
0.0005 seconds; maybe clock() IS dependant on CPU usage...

As usual, I'm confused...

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"?
or your
program is using exactly 1 second of CPU time per second of real time.
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. For example, I'll go ahead
and run it while doing a heavy download from the net and starting
up another big program:

Sleeping for 1 seconds
Slept for 1.001000 seconds
Sleeping for 2 seconds
Slept for 2.000000 seconds
Sleeping for 3 seconds
Slept for 3.003000 seconds
Sleeping for 4 seconds
Slept for 4.004000 seconds

OK, like I said, sometimes it's off by a few thousandths of a second,
but it still managed to sneak in there while everything else was happening
and my second-hand watch perception was that the timings were exactly
as advertised...
But if _sleep(4) consumes a full 4 seconds of CPU time doing nothing.
I think on a modern GUI single-processor system the CPU is always
doing SOMETHING, but the point of the "sleep" stuff is that my program
does NOTHING for a specified period of time...
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, which in this case is
a value supporting millisecond granularity...

---
William Ernest Reid

Sep 12 '07 #9
"Bill Reid" <ho********@happyhealthy.netwrote:
Keith Thompson <ks***@mib.orgwrote in message
Bart van Ingen Schenau <ba**@ingen.ddns.infowrites:
Miguel Guedes wrote:
>{
>target = clock() + (clock_t)(timer*(float)CLOCKS_PER_SEC);
>>
>while(clock() < target);
>
Although this is a standard conforming way to wait for a certain time
period, it is actually not a very friendly way on a multi-user system.
This loop probably consumes 100% CPU time while it is doing nothing.
And it doesn't necessarily do what you want it to do. The clock()
function returns an indication of CPU time, not real time.

Really? Seems to work to a few thousandths of a second
here (note that _sleep() is my development package version of
a sleep/wait/delay function for Windows, and CLK_TCK
is the macro for determining the number of seconds from
clock()):
Seems is correct. It may do so under MS-DOS, when no other program is
running, but it isn't the right function to use for most systems.
For this kind of task, it is advisable to look for a implementation
specific method. Functions like Sleep (Windows) and sleep/usleep (unix)
come to mind.

Yes, I think just about all compilers for general purpose computers
allow you to call in some way a system timer for suspending your program
for a period of time...
Yup. And that's the best way to handle this. Busy-looping is not, unless
you enjoy having your account suspended by your friendly local BOFH.

Richard
Sep 12 '07 #10
"Bill Reid" <ho********@happyhealthy.netwrites:
Keith Thompson <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>"Bill Reid" <ho********@happyhealthy.netwrites:
[...]
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):
[...]
>Perhaps you can shed some light on this.
[...]
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".
[...]
MY OS apparently just returns something that is effectively
the same as "wall clock" time as ITS "approximation" of "processor
time".
[...]
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).
[...]

Stop shouting, and stop treating us like idiots just because we may
have missed (or disagreed with) some point you made. I'm trying to
take part in a technical discussion here. You're welcome to join me
in that endeavor.

Yes, the value returned by the clock() function is an *approximation*.
I'm very well aware of that; I don't expect it to count every CPU
cycle unless the underlying system makes it reasonably easy to do
that.

Unless I've missed something, you still haven't explained what
_sleep() does; you've just insulted me for not already knowing. I
could guess that it behaves similarly to the POSIX sleep() function,
i.e., that it suspends execution of the current program (process,
whatever) for a specified time interval, allowing other programs
(processes, whatever) to use the CPU until the specified interval
expires. But since it's a non-standard function, I didn't see any
point in making even an educated guess when you could easily tell us
what it does.

The point is that, based on your description, buried somewhere within
the insults, your system's clock() function appears to be broken.
Yes, the standard only requires an "approximation", but did you miss
the context: "best approximation"?

If your system's clock() function indicates that your program used 4
seconds of processor time while it was sleeping for 4 seconds and not
using the processor, then I can hardly imagine that that's "the
implementation's best approximation to the processor time used by the
program". A sin() function that always returns 0.0 would be a
similarly bad approximation; you might be able to argue that the
standard allows it, but it would unquestionably be broken.

So the whole point of this discussion is apparently that your
implementation has a broken, or at least non-standard, clock()
function.

You claim that there's a good chance that your program would behave
the same way on a lot of systems. I believe you're mistaken. For one
thing, most systems aren't likely to have a function called '_sleep'.

Here's my version of your program. It depends on the POSIX sleep()
function, but is otherwise standard C. Note that the standard says
only that clock_t is an arithmetic type, so I've allowed for all the
possibilities (floating, unsigned, and signed). I've also used the
standard CLOCKS_PER_SEC macro rather than CLK_TCK. And I've examined
the result of clock() again after performing some CPU-intensive
calculatations. A decent optimizer could eliminate the calculations,
but I compiled the program without asking for optimization. If
necessary, I could have declared 'result' as volatile.

I observed, as the program ran, that each sleep(N) call took
approximately N seconds (I didn't time it precisely).

================================================== ======================
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <math.h>

static void show_clock(clock_t c)
{
if ((clock_t)1 / 2 (clock_t)0) {
/* clock_t is floating-point */
printf("%f", (double)c);
}
else if ((clock_t)-1 (clock_t)0) {
/* clock_t is unsigned */
printf("%luU", (unsigned long)c);
}
else {
/* clock_t is signed */
printf("%ld", (long)c);
}
}

static void do_stuff(void)
{
#define ITERATIONS 10000000
long i;
double result;
for (i = 0; i < ITERATIONS; i ++) {
result = sin((double)i/ITERATIONS);
}
}

int main(void)
{
int inc;
clock_t start, end;

printf("CLOCKS_PER_SEC = ");
show_clock(CLOCKS_PER_SEC);
putchar('\n');

for (inc = 1; inc < 5; inc++) {
printf("Sleeping for %d seconds\n", inc);
start = clock();
sleep(inc);
end = clock();

printf("start = ");
show_clock(start);
printf(", end = ");
show_clock(end);
putchar('\n');

printf("Slept for %f seconds of processor time\n",
(((double)end-start)/CLOCKS_PER_SEC));
}

do_stuff();
printf("After computations, clock() returns ");
show_clock(clock());
putchar('\n');

return 0;
}
================================================== ======================

And here's the output I got on one system:
================================================== ======================
CLOCKS_PER_SEC = 1000000
Sleeping for 1 seconds
start = 0, end = 0
Slept for 0.000000 seconds of processor time
Sleeping for 2 seconds
start = 0, end = 0
Slept for 0.000000 seconds of processor time
Sleeping for 3 seconds
start = 0, end = 0
Slept for 0.000000 seconds of processor time
Sleeping for 4 seconds
start = 0, end = 0
Slept for 0.000000 seconds of processor time
After computations, clock() returns 940000
================================================== ======================

The amount of processor time consumed by each sleep() call was
approximately zero; it was not anywhere near the wall clock time
consumed. This was very different from the results you got.

If you reply to this with another long screed full of insults, words
in all-caps, and repeated exclamation points, I will ignore you. If
you care to calm down and discuss technical issues, I'll be glad to
continue the discussion. It's up to you.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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"
Sep 19 '07 #11
On Tue, 25 Sep 2007 01:59:48 GMT, in comp.lang.c , "Bill Reid"
<ho********@happyhealthy.netwrote:

>Keith Thompson <ks***@mib.orgwrote in message
>Stop shouting, and stop treating us like idiots just because we may
have missed (or disagreed with) some point you made.

OK, "you" ("us") first...
No, you first. You're the one shouting.
>I'm trying to
take part in a technical discussion here. You're welcome to join me
in that endeavor.

I like technical discussions, except I'm really not that technically
knowledgeable,
Then you are hardly qualified to comment.
>.this sometimes
goads people who are not very technically knowledgeable but rely
on a resume indicating technical knowledge to "take advantage"...
In other words, you like trolling, and think its amusing.

>Unless I've missed something, you still haven't explained what
_sleep() does; you've just insulted me for not already knowing.

I don't KNOW what it does either! I just ASSUME
Then what on earth makes you think you can insult other people for not
knowing?

Either you're a knave or a fool. Which is it?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 25 '07 #12
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
....
>If I were you, I'd complain to your vendor about it. But then again,
if I were you I'd try not to be such a rude long-winded blithering
idiot.
Granted. You are rarely long-winded.

Oct 10 '07 #13

Mark McIntyre <ma**********@spamcop.netwrote in message
news:ji********************************@4ax.com...
On Tue, 25 Sep 2007 01:59:48 GMT, in comp.lang.c , "Bill Reid"
<ho********@happyhealthy.netwrote:
Keith Thompson <ks***@mib.orgwrote in message
Stop shouting, and stop treating us like idiots just because we may
have missed (or disagreed with) some point you made.
OK, "you" ("us") first...

No, you first. You're the one shouting.
Actually, it IS impossible to "shout" online, but in terms of treating
people like idiots, I neither started that nor am I the worst offender...
I'm trying to
take part in a technical discussion here. You're welcome to join me
in that endeavor.
I like technical discussions, except I'm really not that technically
knowledgeable,

Then you are hardly qualified to comment.
Another "hit" on the bait...
.this sometimes
goads people who are not very technically knowledgeable but rely
on a resume indicating technical knowledge to "take advantage"...

In other words, you like trolling, and think its amusing.
No. In real life, I hate liars and fakes, primarily because I like
to get stuff done, and liars and fakes hopelessly gum up a rational
work process. My first impulse to just to let them be liars and
fakes somewhere else...
Unless I've missed something, you still haven't explained what
_sleep() does; you've just insulted me for not already knowing.
I don't KNOW what it does either! I just ASSUME

Then what on earth makes you think you can insult other people for not
knowing?
Being well-informed, logical, and correct has its advantages...maybe
someday you'll try that path instead of the one you're on...
Either you're a knave or a fool. Which is it?
I'm the brave knight of rational productivity in the kingdom of
BSing fakes...

---
William Ernest Reid

Oct 10 '07 #14
"Bill Reid" <ho********@happyhealthy.netwrote:
gets(choice);
So. You really _are_ trolling, then? Glad to know it.

Richard
Oct 10 '07 #15
Bill Reid wrote:

I dangled that little piece of bait
Ah, just another troll. Sorry, but that position is more than filled
already.

*plonk*

Brian
Oct 10 '07 #16
In article <W6*********************@bgtnsc04-news.ops.worldnet.att.net>,
Bill Reid <ho********@happyhealthy.netwrote:
>Keith Thompson <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>And it doesn't necessarily do what you want it to do. The clock()
function returns an indication of CPU time, not real time.
>Really? Seems to work to a few thousandths of a second
here (note that _sleep() is my development package version of
a sleep/wait/delay function for Windows, and CLK_TCK
is the macro for determining the number of seconds from
clock()):
With a slight modification to your program to remove the dos dependancy:

#include <stdio.h /* required to breathe */
#include <time.h /* required for clock functions */

int main(void) {
int inc;
clock_t start,end;

for(inc=1;inc<5;inc++) {
printf("Sleeping for %d seconds\n",inc);
start=clock();
sleep(inc);
end=clock();
printf("Slept for %f seconds\n",((double)(end-start)/CLK_TCK));
}
}

$ uname -a
IRIX64 origin 6.5 10151453 IP27
$ ./sleepy
Sleeping for 1 seconds
Slept for 0.000000 seconds
Sleeping for 2 seconds
Slept for 0.000000 seconds
Sleeping for 3 seconds
Slept for 0.000000 seconds
Sleeping for 4 seconds
Slept for 0.000000 seconds

/tmp 1081uname -a
Linux hydra05 2.6.10-1.770_FC3smp #1 SMP Thu Feb 24 18:36:43 EST 2005 x86_64 x86_64 x86_64 GNU/Linux
/tmp 1080./sleepy
Sleeping for 1 seconds
Slept for 0.000000 seconds
Sleeping for 2 seconds
Slept for 0.000000 seconds
Sleeping for 3 seconds
Slept for 0.000000 seconds
Sleeping for 4 seconds
Slept for 0.000000 seconds
So Yes, although clock() might have happened to have returned real
time on -your- system, it is defined as returning processor time, and
that is what it actually returns on some very different systems.

The matter is easily resolved by supposing that on your system,
the "system's best approximation of processor time" is clock time.
No big deal; other implementations have better approximations.
--
We regret to announce that sub-millibarn resolution bio-hyperdimensional
plasmatic space polyimaging has been delayed until the release
of Windows Vista SP2.
Oct 10 '07 #17
On Wed, 10 Oct 2007 03:52:35 GMT, in comp.lang.c , "Bill Reid"
<ho********@happyhealthy.netwrote:
>
Mark McIntyre <ma**********@spamcop.netwrote in message
news:ji********************************@4ax.com.. .
>On Tue, 25 Sep 2007 01:59:48 GMT, in comp.lang.c , "Bill Reid"
>I don't KNOW what it does either! I just ASSUME

Then what on earth makes you think you can insult other people for not
knowing?

Being well-informed, logical, and correct has its advantages...
It does. However since you above admitted you aren't well informed,
you seem to be hoist by your own petard.
>Either you're a knave or a fool. Which is it?

I'm the brave knight of rational productivity in the kingdom of
BSing fakes...
You are Karl the Chair, and I claim my five pounds.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 11 '07 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: david wolf | last post by:
I have a function called void f(){ char * tmp = "abc"; static * tmp1 = "abcd"; } Can anyone tell me 1)whether pointer tmp is stored in stack or heap? 2)whether string "abc" of length 4 bytes...
2
by: M Maloney | last post by:
Hey all, I was wondering if anyone could help me with this problem I have: Given a text file like this: 8 =ABC 18.00 Dr Who: Underworld 18.30 Collectors 19.00 News
2
by: Danny | last post by:
Hi all, I hope you can help me. I have a access 2002 database of customers from and they are grouped by department in this database. Each record has a sale price for a purchase they made with...
3
by: Kathy Burke | last post by:
Hi, I'm tired, so this question may be silly. I have a fairly long sub procedure. Based on one condition, I load another sub with the following: If Session("GRN") = "complete" Then txtScan.Text...
14
by: felixnielsen | last post by:
Consider this 3d vector: const SIZE = 'some_size'; std::vector<std::vector<std::vector<char> > >GRID(SIZE, std::vector<std::vector<char> >(SIZE, std::vector<char>(SIZE))); It can be viewed...
3
by: Senna | last post by:
Hi Have these to work with. int counter = 0; //The total item to fill the collection with int increment = 2; //Any number int current = 244; //Quantity int max = 1290; //Max Quantity int...
28
by: birensubudhi | last post by:
1) void foo(char *s,char *t) { while(*s++=*t++); } which C function is equivalent to foo ? 2) #define ROUND(x,n)
17
by: Liam Gibbs | last post by:
Hello everyone, I'm having a problem with a site I'm building. It uses tables, but it's really tricky. A picture of the layout I need can be found at http://www.altmarvel.net/Liam/WHATINEED.jpg...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.