runtime log

H

Huibuh

I want to check the runtime of a part of my program. I chose



#include <time.h>



int runtime

time_t start, end;



start=time(NULL);

end=time(NULL);

runtime=difftime (end, start);



The result was zero, so obviously it is not exact enough. I found the
function CLOCK icw CLOCKS_PER_SEC but I have no idea how to use.



Any idea?

Thanks in advance Dieter
 
V

Victor Bazarov

Huibuh said:
[...] I found the
function CLOCK icw CLOCKS_PER_SEC but I have no idea how to use.



Any idea?

How about you read a reference or something? Go Google for it
and you will find plenty of information. Why involve other human
beings into what you can do alone?
 
R

Robbie Hatley

Huibuh said:
time_t start, end;
start=time(NULL);
end=time(NULL);
runtime=difftime (end, start);

The result was zero

The time elapsed between two executive commands on most modern
computers is something around a nanosecond. Yes, that's pretty
damn close to zero. And since it's certainly much less than
than one tick of your timer, yes, you will get zero.

Try something like this:

double trouble = 0.000386;
start=time(NULL);
for (long int i = 0; i<1000000000; ++i)
{
trouble *= 1.000238; // waste some time
}
end=time(NULL);

I think you'll find the elapsed time is no longer zero.



--
Cheers,
Robbie Hatley
Tustin, CA, USA
email: lonewolfintj at pacbell dot net
web: home dot pacbell dot net slant earnur slant
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,516
Latest member
ChrisHibbs

Latest Threads

Top