gettimeofday() should never be used to measure time
gettimeofday() and time() should only be used to get the current time if the current
wall-clock time is actually what you want. They should never be used to
measure time or schedule an event X time into the future.
What's the problem?
gettimeofday() returns the current wall clock time and timezone. time() returns a
subset of this info (only whole seconds, and not timezone).
Using these functions in order to measure the passage of time (how long an operation took)
therefore seems like a no-brainer. After all, in real life you measure by checking your watch
before and after the operation. The differences are:
1. Nobody sneaks in and changes your wristwatch when you're not looking
You usually aren't running NTP on your wristwatch, so it probably won't jump a second or two (or 15 minutes)
in a random direction because it happened to sync up against a proper clock at that point.
Good NTP implementations try to not make...