clock_gettime(CLOCK_MONOTONIC) is what serious C benchmarking code uses instead of gettimeofday(), because NTP or manual clock adjustments can step the wall clock backwards mid-measurement and silently corrupt a benchmark. Getting the monotonic-clock choice and nanosecond-to-millisecond math right here is the same discipline that keeps production services from ever reporting a nonsensical negative elapsed time.