I have this problem and I can’t figure out how to solve it.
I have to measure the time required to perform a certain function. Well, the stopwatch function measuring time in milliseconds was not good enough, so I used the measurement in nanoseconds.
The problem is that the function ends so quickly, even a stopwatch in nano seconds cannot measure it.
I know that the stopwatch works because I tried adding, for example, Thread.sleep(1) to my function (Thread.sleep in milliseconds), and I get my time, but without Thread.sleep my time is always 0. Any ideas ?
Here is my code:
long startTimeLocalNS=0; long stopTimeLocalNS = 0; startTimeLocalNS = System.nanoTime(); if (something) { } stopTimeLocalNS = System.nanoTime(); disconnectTime = (stopTimeLocalNS - startTimeLocalNS);
source share