i want to calculate the exact run time of my program in seconds....i used clock() function of time.h library...
what i did is that i made two clock_t type objects...
initialized one of them in the start of main() function and the other in the end..
and calculated the difference..as shown...


clock_t start,end;
my code.

but i want to know what does that difference shows...what's its unit...seconds..milliseconds..microseconds..or depends on clock frequency...???
Am using Dev-c++...

Recommended Answers

All 5 Replies

>what's its unit...seconds..milliseconds..microseconds..
>or depends on clock frequency...???
From a standard library perspective, you don't know. Everything after this point assumes non-portable things about your implementation.

You can divide the result by CLOCKS_PER_SEC and get the result in seconds, but be sure to cast one of those operands to a floating-point type or you'll likely get a lot of zeros unless your program takes more than a second.

But where is CLOCK_PER_SEC declared...i divided it..but it gives compile time error...that it is undeclared...i have included ctime.h library...but still it gives the error...what's the solution??

and what is CLOCK_PER_SEC..what does it denote??

>what's the solution??
Spell it correctly. It's CLOCKS_PER_SEC, not CLOCK_PER_SEC, and it's defined in ctime.

i got it..
the output is in seconds,right??

>the output is in seconds,right??
That's what I said:

You can divide the result by CLOCKS_PER_SEC and get the result in seconds

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.