This code is the simplest code to measure a program execution time more precisely.
It is using “struct timeval”.
double getTimeElapsed(struct timeval end, struct timeval start)
return (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.00;
struct timeval tvalBefore, tvalAfter;
// Do something here, this is the simplest program to measure the elapsed time. It is more precise than simple ctimer
double time_elapsed = getTimeElapsed(tvalAfter, tvalBefore);
I have referred the below two sites
Good luck ^_^