System.nanoTime() to measure execution time of an algorithm
807607Oct 2 2006 — edited Oct 2 2006Would it be advisable to use System.nanoTime() to accurately measure the execution time of an algorithm? I have tried using System.currentTimeMillis() but it always returns me the value ms. (I am trying to measure the execution time for a Binary Search). What worries me is this statement from the API.
"This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change"
It would appear that this would not give an accurate measurement of the actual time it takes for the algorithm to execute isn't it?