summaryrefslogtreecommitdiff
path: root/java/lang/System.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-06-04 18:15:04 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-06-04 18:15:04 +0000
commitd0ebd06d728f4b2fefd2e18e6c58684f62bd2673 (patch)
treebcca7d0f7e5ccd0438a8e0dac44c9e37520a4388 /java/lang/System.java
parent85ab115d6203b30467c64335e4f74ec75a8f33a9 (diff)
downloadclasspath-d0ebd06d728f4b2fefd2e18e6c58684f62bd2673.tar.gz
2006-03-20 Andrew John Hughes <gnu_andrew@member.fsf.org>
* java/lang/System.java: (nanoTime()): Documented. 2006-03-20 Tom Tromey <tromey@redhat.com> * java/lang/System.java: (nanoTime()): Implemented.
Diffstat (limited to 'java/lang/System.java')
-rw-r--r--java/lang/System.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/java/lang/System.java b/java/lang/System.java
index bb9715f6f..19278aa32 100644
--- a/java/lang/System.java
+++ b/java/lang/System.java
@@ -222,6 +222,36 @@ public final class System
return VMSystem.currentTimeMillis();
}
+ /**
+ * <p>
+ * Returns the current value of a nanosecond-precise system timer.
+ * The value of the timer is an offset relative to some arbitrary fixed
+ * time, which may be in the future (making the value negative). This
+ * method is useful for timing events where nanosecond precision is
+ * required. This is achieved by calling this method before and after the
+ * event, and taking the difference betweent the two times:
+ * </p>
+ * <p>
+ * <code>long startTime = System.nanoTime();</code><br />
+ * <code>... <emph>event code</emph> ...</code><br />
+ * <code>long endTime = System.nanoTime();</code><br />
+ * <code>long duration = endTime - startTime;</code><br />
+ * </p>
+ * <p>
+ * Note that the value is only nanosecond-precise, and not accurate; there
+ * is no guarantee that the difference between two values is really a
+ * nanosecond. Also, the value is prone to overflow if the offset
+ * exceeds 2^63.
+ * </p>
+ *
+ * @return the time of a system timer in nanoseconds.
+ * @since 1.5
+ */
+ public static long nanoTime()
+ {
+ return VMSystem.nanoTime();
+ }
+
/**
* Copy one array onto another from <code>src[srcStart]</code> ...
* <code>src[srcStart+len-1]</code> to <code>dest[destStart]</code> ...