tag:blogger.com,1999:blog-5053057173658248087.post5158264207740911628..comments2022-09-10T13:57:04.046+03:00Comments on ChaiPuter: Java Stopwatchavihttp://www.blogger.com/profile/02331681113034830912noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5053057173658248087.post-55237289589935736772012-08-10T12:34:06.948+03:002012-08-10T12:34:06.948+03:00I don't know.
I assume it is more accurate th...I don't know.<br /><br />I assume it is more accurate than just getting the milliseconds.<br /><br />I can only quote the javadocs:<br /><br /><br />An object that measures elapsed time in nanoseconds. It is useful to measure elapsed time using this class instead of direct calls to System.nanoTime() for a few reasons:<br /><br />An alternate time source can be substituted, for testing or performance reasons.<br />As documented by nanoTime, the value returned has no absolute meaning, and can only be interpreted as relative to another timestamp returned by nanoTime at a different time. Stopwatch is a more effective abstraction because it exposes only these relative values, not the absolute ones.<br />Basic usage:<br /><br /> Stopwatch stopwatch = new Stopwatch().start();<br /> doSomething();<br /> stopwatch.stop(); // optional<br /><br /> long millis = stopwatch.elapsedMillis();<br /><br /> log.info("that took: " + stopwatch); // formatted string like "12.3 ms"avihttps://www.blogger.com/profile/02331681113034830912noreply@blogger.comtag:blogger.com,1999:blog-5053057173658248087.post-52281914042163966082012-08-09T09:51:44.875+03:002012-08-09T09:51:44.875+03:00Thanks, Avi. I'm curious about the nano-secon...Thanks, Avi. I'm curious about the nano-second precision: Given the fact that code almost-always runs under a preemptive-multitasking OS, which plays hell with the timing of individual code events, it that kind of precision meaningful?Michael Berkowitznoreply@blogger.com