this will help Profiling may be an easier option since you don't require in-production stats. Profiling also doesn't require code modification. VisualVM (which ships w/ the JDK 1.6.06+) is a simple tool. If you want something more in-depth I'd go with Eclipse TPTP, Netbeans profiler, or JProfiler(pay). If you want to write you own, consider the following:
long start = System.nanoTime(); // requires java 1.5
// Segment to monitor
double elapsedTimeInSec = (System.nanoTime() - start) * 1.0e-9;
Measuring the execution time of any piece of code in PHP, getting negative result
this will help Floating point arithmetic seems to be a hassle, so I'm trying to avoid it as much as possible. The problem with the OP code was that only the microseconds part of the result was used. Consequently, if duration of the execution exceeds one second, the end result can be a negative difference.