![]() |
|
![]() | ||
|
Subject:
the study of the ticking of some computer clock
Category: Computers > Programming Asked by: damonguitar-ga List Price: $5.00 |
Posted:
19 Oct 2002 11:26 PDT
Expires: 18 Nov 2002 10:26 PST Question ID: 85194 |
here is the programming excercise picked up from the book. however i got no clue how to do it. here is the question! under c++ sofrware, determine the true tick rate which is not equal to CLOCKS_PER_SEC and CLK_TCK. your program must keep calling clock(), and record the new value each time it changes. u are to do this for at leat 1000 true ticks. for each tick, print the number of the tick (1,2,3,- - - -), and the number of calls to clock() before the value changed. print the values for either 4,5 or 8 ticks per line. Also, please explain the steps u do in the program. "thanks for helping" |
![]() | ||
|
Subject:
Re: the study of the ticking of some computer clock
Answered By: leapinglizard-ga on 26 Oct 2002 18:24 PDT |
The exercise statement implies that a "true tick" is what takes place whenever the value of clock() changes. The object, oddly enough, is to count how many clock() calls we can make between "true ticks". There is a kind of Heisenberg Principle at work here: by introducing instructions to tally the number of count() calls, we are reducing the number of calls we can make in a given span of time. Nonetheless, the following ISO-compliant C++ program does what the exercise requires. You'll note that I've included copious comments which are uniformly indented in my editor, but not necessarily in yours. // ticks.cc #include<stdlib.h> #include<stdio.h> #include<time.h> using namespace std; #define MAX 1000 // program runs for MAX true ticks #define BREAK 8 // we'll display BREAK ticks per line int main() { int tick = 0, count = 0; // tick = elapsed ticks; count = calls per tick clock_t curr = clock(); // set current clock() value while (1) { count++; // update number of calls if (clock() == curr) // compare current clock() value continue; // if unchanged, return to head of loop printf("%d:%d ", ++tick, count); if (tick % BREAK == 0) // print newline after every eight ticks printf("\n"); if (tick == MAX) break; // leave loop if MAX ticks have elapsed count = 0; // reset number of calls curr = clock(); // update clock() value } return 0; // end program } Regards, leapinglizard |
![]() | ||
|
Subject:
Re: the study of the ticking of some computer clock
From: efn-ga on 25 Oct 2002 19:53 PDT |
The clock function gives you the amount of processor time your process has used, measured in "ticks." A tick is not a standard, absolute unit of time like a second, it's implementation-dependent or platform-dependent. That is, a tick may be different amounts of time with different operating systems or hardware. Most likely, your program can read the clock more than one time per tick, whatever a tick may be. So if you write a loop that just reads the clock over and over, you will get the same value back from the clock function over and over until your program has used a tick of processor time, and then you will get a value that is one higher. The exercise says your program should do just that and count the number of times it can call clock before it gets a different value. It's pretty bogus to refer to this as determining "the true tick rate." The information you get doesn't tell you anything about the number of ticks in a second, which I think is what "tick rate" should refer to. It only tells you about how many times you can call clock per tick. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |