How to get the running of time of my program with gettimeofday()
Posted
by Mechko
on Stack Overflow
See other posts from Stack Overflow
or by Mechko
Published on 2010-01-23T23:36:58Z
Indexed on
2010/04/21
6:43 UTC
Read the original article
Hit count: 310
So I get the time at the beginning of the code, run it, and then get the time.
struct timeval begin, end;
gettimeofday(&begin, NULL);
//code to time
gettimeofday(&end, NULL);
//get the total number of ms that the code took:
unsigned int t = end.tv_usec - begin.tv_usec;
Now I want to print it out in the form "**code took 0.007 seconds to run" or something similar.
So two problems:
1) t seems to contain a value of the order 6000, and I KNOW the code didn't take 6 seconds to run.
2) How can I convert t to a double, given that it's an unsigned int? Or is there an easier way to print the output the way I wanted to?
© Stack Overflow or respective owner