While working for at Persistent Systems Pvt. Ltd., Pune, we developed a small library with Java and C++ wrappers to implement very high resolution timers. We use these timers to count the ticks when doing performance analysis and stuff like that. I would like to thank Nikhil Deshpande and Chandraprakash Jain, my seniors at work, in helping me out while I was working on this tool. Infact, the java wrapper for this library is a contribution from Nikhil.
The library I developed exploited the system dependent timers / clocks and provided a timer like interface to the same. The library, compiles and functions on Linux, Solaris and Windows. The attached file, has build scripts for Linux and Solaris. There is also a Java wrapper over the library, which uses JNI to use the timer interfaces.
My observation is that while Linux system timers allow a resolution to count till microseconds, a Solaris box can provide resolution to nanosecond levels.
The code is pretty dirty when it comes to system specific decisions, but provides a clean interface - complete with error message details, error handling, easy to use functions, extensible and customizable design.
The ReadMe.txt file, explains some of the stuff that I've done. Click here to read the file, without having to download the entire code. The library is LGPL licensed - you are free to use, redistribute and modify the same to suit your requirement, as long as you confirm the license agreement.
Click on the links below to download the source code for the high resolution timer library :