title: Precision vs. accuracy of System.nanoTime()
body: <p>The documentation for <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#nanoTime()" rel="noreferrer"><code>System.nanoTime()</code></a> says the following (emphasis mine).</p>
  
  <blockquote>
    <p>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). <strong>This method provides nanosecond precision, but not necessarily nanosecond accuracy.</strong> No guarantees are made about how frequently values change.</p>
  </blockquote>
  
  <p>As I see it, this can be interpreted in two different ways:</p>
  
  <ol>
  <li><p>The sentence in <strong>bold</strong> above refers to individual return values. Then, precision and accuracy are to be understood in the numerical sense. That is, precision refers to the number of significant digits - the position of truncation, and accuracy is whether the number is the correct one (such as described in the top answer here
  <a href="https://stackoverflow.com/questions/8270789/what-is-the-difference-between-precision-and-accuracy">What is the difference between &#39;precision&#39; and &#39;accuracy&#39;?</a> )</p></li>
  <li><p>The sentence in <strong>bold</strong> above refers to the capability of the method itself. Then, precision and accuracy are to be understood as illustrated by the dartboard analogy
  ( <a href="http://en.wikipedia.org/wiki/Precision_vs._accuracy#Accuracy_versus_precision:_the_target_analogy" rel="noreferrer">http://en.wikipedia.org/wiki/Precision_vs._accuracy#Accuracy_versus_precision:_the_target_analogy</a> ).
  So, low accuracy, high precision => the wrong value is repeatedly hit with a high precision: imagining that physical time stands still, consecutive calls of nanoTime() returns the same numerical value, but it is off from the actual elapsed time since the reference time by some <em>constant</em> offset.</p></li>
  </ol>
  
  <p>Which interpretation is the correct one? My point is, interpretation 2 would mean that a measure of time <em>difference</em> using nanoTime() (by subtracting two return values) would be correct to the nanosecond (since the constant error/offset in the measurement would be eliminated), while interpretation 1 wouldn't guarantee that kind of compliance between measurements and thus wouldn't necessarily imply a high precision of time difference measurements.</p>
  
  <hr>
  
  <p><strong>Updated 4/15/13:</strong> The Java 7 documentation for <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime()" rel="noreferrer"><code>System.nanoTime()</code></a> has been updated to address the possible confusion with the previous wording.</p>
  
  <blockquote>
    <p>Returns the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds.</p>
    
    <p>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 <em>origin</em> time (perhaps in the future, so values may be negative). The same origin is used by all invocations of this method in an instance of a Java virtual machine; other virtual machine instances are likely to use a different origin.</p>
    
    <p>This method provides nanosecond precision, but not necessarily nanosecond resolution (that is, how frequently the value changes) - no guarantees are made except that the resolution is at least as good as that of <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#currentTimeMillis()" rel="noreferrer"><code>currentTimeMillis()</code></a>.</p>
    
    <p>Differences in successive calls that span greater than approximately 292 years (2<sup>63</sup> nanoseconds) will not correctly compute elapsed time due to numerical overflow.</p>
    
    <p>The values returned by this method become meaningful only when the difference between two such values, obtained within the same instance of a Java virtual machine, is computed.</p>
  </blockquote>