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?