I’m writing something basic in c that times how long it takes to execute a shell script.
I have
gettimeofday(&start, NULL);
// code here
gettimeofday(&end, NULL);
// print end - start
I know that the timeval struct has tv_sec and tv_usec which I accounted for but even for scripts such as “sleep 3” I’m still getting 0 for this end – start difference. Any guesses as to why?
You should read this: gettimeofday() should never be used to measure time
Try
clock_gettime(CLOCK_MONOTONIC, ...)instead.