Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

My kingdom for a good timer!

Reach submillisecond timing precision in Java

  • Print
  • Feedback

Page 2 of 2

duration = 0.004 ms
duration = 0.006 ms
duration = 0.005 ms
duration = 0.004 ms
duration = 0.004 ms


Even with added Java and JNI method dispatch overhead, you can count on sub-10 microsecond resolution on a good system. This is orders of magnitude better than any other profiling options I've tried. As mentioned in Resources (Java Tip 92), commercial analysis tools based on the Java Virtual Machine Profiler Interface (JVMPI) won't beat the directness and simplicity of my approach, since the relevant JVMPI profiling methods are based on the same low-resolution system timer calls and require additional analysis to extrapolate measured data correctly.

I hope you find this article and the implementation code (downloadable in Resources) useful in your own work. I have been using it for several years when profiling general-purpose Java code, Java Database Connectivity queries, Java file and socket input/output, HTTP and Remote Method Invocation method call overhead, and many other code segments not quite "slow enough" to work well with the default system timer and when the full machinery of commercial profiling tools is an overkill.

About the author

Vladimir Roubtsov has programmed in a variety of languages for more than 12 years, including Java since 1995. Currently, he develops enterprise software as a senior developer for Trilogy in Austin, Texas.
  • Print
  • Feedback

Resources