Why gettimeofday() is bad at timing things

I was reading a changelog from a library I love (unrelated but here is the link: https://liballeg.org/ ) and I stumble upon that change:


“Use clock_gettime with CLOCK_MONOTONIC instead of gettimeofday (check-switch-26)”

Then I did a bit of research on the topic, and found a good explanation here:

https://blog.habets.se/2010/09/gettimeofday-should-never-be-used-to-measure-time.html

TLDR: if you use gettimeofday to time things then your program may be affected by time shift, because gettimeofday is not monotonic. if you do not care about the date and only about elapsed time, use clock_gettime.