I am trying to write a benchmark program that takes about 20 minutes to complete because the actual functions need to be called at least 50 times.
I used the following code:
struct timeval start, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
usleep(2000);
gettimeofday(&end,NULL);
seconds =end.tv_sec - start.tv_sec;
useconds=end.tv_usec - start.tv_usec;
(mtime>1000)?cout<<"elapsed time in seconds:"<<setprecision(8)<<mtime/1000<<"seconds\n":cout<<"elapsed time in milliseconds: "<<setprecision(3)<<mtime<<" milliseconds\n";
but I am required to write it in such a way that the output deduces the best units to use for the elapsed time and displays the results in those units. any suggestions how I can revise the above code for the requirement? thx!
My guess is that your “best unit” requirement is basically “human usable units.” If so, take the time and
and so on.