Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

System.nanoTime() to measure execution time of an algorithm

807607Oct 2 2006 — edited Oct 2 2006
Would 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 30 2006
Added on Oct 2 2006
3 comments
921 views