nanotime

Is System.nanoTime() completely useless?

As documented here, on x86 systems. Java's System.nanoTime() returns the time value using a cpu specific counter. Now consider the following case I use to measure time of a call - long time1= System.nanotime(); foo(); long time2 = System.nanotime(); long timeSpent = time2-time1; Now in a multi core system, it could be that after measu...

strace java applet

I'm trying to strace a java applet, and strace doesn't seem to be working. I'm calling the following function. public static void testSTrace(){ long c = 0; for (int i = 0; i < 1000; i++){ long start = System.nanoTime(); try{Thread.sleep(0, 100);}catch(Exception e){/*cry*/} long stop = System.nanoTime(); log.info("start : " ...

What is the equivalent to System.nanoTime() in .NET?

The title is pretty much self-explanatory, I'm killing myself over this simplicity. Looked here, but it isn't much helpful. ...

System.nanotime running slow?

One of my friends showed me something he had done, and I was at a serious loss to explain how this could have happened: he was using a System.nanotime to time something, and it gave the user an update every second to tell how much time had elapsed (it Thread.sleep(1000) for that part), and it took seemingly forever (something that was wa...

Is System.nanoTime() consistent across threads?

I want to count the time elapsed between two events in nanoseconds. To do that, I can use System.nanoTime() as mentioned here. The problem is that the two events are happening in different threads. Since nanoTime() doesn't return an absolute timestamp but instead can only be used to calculate time differences, I'd like to know if the...

Why is my System.nanoTime() broken?

Myself and another developer on my time recently moved from a Core 2 Duo machine at work to a new Core 2 Quad 9505; both running Windows XP SP3 32-bit with JDK 1.6.0_18. Upon doing so, a couple of our automated unit tests for some timing/statistics/metrics aggregation code promptly started failing, due to what appear to be ridiculous va...

How to get a meaningful result from subtracting 2 nanoTime objects?

I created a filter that monitors the length of a request. long start = System.nanoTime(); ... long end = System.nanoTime(); How can I get the number of milliseconds from this now? ...