summaryrefslogtreecommitdiff
path: root/java/lang/System.java
diff options
context:
space:
mode:
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> ...