>I want to calculate the running time of my program, which runs for a
long time(~ a day).
clock() measures CPU time, which is a lot like football or basketball
game clock time: it doesn't run all the time.
#include <time.h>
clock_t tend, tstart;
tstart = clock();
\* Body of Code *\
^^ this is a syntax error
tend = clock();
Running Time = ((double) (tend - tstart) / (double) CLOCKS_PER_SEC));
^ extra )
Check out the data type of clock_t and the value of CLOCKS_PER_SEC.
If, for example, clock_t is 32 bits signed and CLOCKS_PER_SEC is
1,000,000 then clock_t overflows at about 0.6 hours.
But for my codes which run for a long time, I am not getting the right
value for the running time variable. Please help me out!!
How do you know it's wrong? If it's negative, it probably overflowed.
If it's just too low, well, a program sitting at an input prompt
for a few decades might well accumulate only a few milliseconds of
CPU time, if that much. Or it might have overflowed.
The only solution I know of to overflow is to take samples more often
(yes, this can be a pain), convert to better units in a floating-point
variable, and add up the results.
Gordon L. Burditt