Finally, a technical post I feel worthy of commenting on.
Performance of my application changes from time(3) to gettimeofday(2). Why? -Joe Open Source Developer
Doh! Really common question and should be an FAQ at this point.... or it is, but an under-published FAQ that only the performance wonks seem to know or run into as an issue. In short, gettimeofday* == EBAD && clock_gettime* == EGOOD. I think the best discussion on this is PHK's post titled Timers and timing, was: MySQL Performance 6.0rc1. Please read. Essentially, FreeBSD*'s gettimeofday* syscall is monotonic, highly accurate and precise, and Linux's is not. Therefore, Linux's gettimeofday* syscall is faster and less accurate than FreeBSD*'s. I happen to agree that gettimeofday* should be monotonic and I take issue with Linux*'s gettimeofday* implementation. Monotonic time keeping requires CPU synchronization (which gettimeofday* does under FreeBSD* and should be done under all operating systems) and will always be slow as a result. Most applications that do not require precise time synchronization across threads and CPUs should use clock_gettime* with a clock_id of CLOCK_REALTIME_FAST. Few applications actually need highly precise, highly accurate, monotonic time measurement and instead can skid by with highly precise, accurate, but non-monotomic time keeping. And now you know.