nickbruun/hayai — pull request #5 by lazarenko (2013-12-18 05:05:37+00:00)
Title: Use better clocks depending on the system.

Using gettimeofday() is not the best way to get the clock due to few reasons:

1. It does not support higher than a microsecond resolution.
2. It cannot get non-adjusted clock (i.e. time can be changed by NTP or adjtime()).
3. It is declared obsolete by recent POSIX standard revision.

I've sketched up a few alternatives. On Linux - use clock_gettime() to query hardware real-time monotonic clock (or non-HW for older kernels). Apple implementation uses mach absolute time. Otherwise fall back to gettimeofday.

clock_gettime() can also be used for FreeBSD and possibly a bunch of other systems but I don't have access to those to play with.

If you like this change, and if I have some time, CPU cycles (TSC, perf events, context switch and CPU migration counters).

I think it might also make sense to switch to nanosecond precision (i.e. use double to store microseconds and print more precise values like `+5.612345` instead of `+5.600000`).