Nanosecond Timing

My Uni (RMIT) uses a mixture of Solaris, Mac OS X, Linux, and Windows computer labs. Our programs are nearly always tested on Solaris, though. Sometimes we are required to provide nanosecond timings in our experiments using the (real-time) POSIX function gethrtime().

Depending on which lab I work in, or if I’m working from home, I might need to comment out (or add compile guards) into my code to compile it correctly. This can make the code less readable, and can make its behavior (particularly output) on Solaris less obvious while testing on a foreign system.

Although the granularity, accuracy and any possible side effects (such as function overhead, or being affected by changing the system clock) may be different for each function, I find it helps to at least give a ball-park figure. Experiments should still be done on Solaris. If you want to use or modify my nanosecond function call wrapper, get it on GitHub.

Note: Not thoroughly tested on all target operating systems or compilers. It is only intended as a convenience.