title: setInterval timing slowly drifts away from staying accurate
body: <p>It seems that when I <code>setInterval</code> for 1000ms, it actually fires the function every 1001ms or so.  This results in a slow temporal drift the longer its running.</p>
  <pre><code>var start;
  var f = function() {
      if (!start) start = new Date().getTime();
      var diff = new Date().getTime() - start;
      var drift = diff % 1000;
      $('&lt;li&gt;').text(drift + &quot;ms&quot;).appendTo('#results');
  };
  
  setInterval(f, 1000);
  </code></pre>
  <p>When run this shows the inaccuracy immediately.</p>
  <ul>
  <li>0ms</li>
  <li>1ms</li>
  <li>2ms</li>
  <li>3ms</li>
  <li>4ms</li>
  <li>5ms</li>
  <li>5ms</li>
  <li>7ms</li>
  <li>8ms</li>
  <li>9ms</li>
  <li>9ms</li>
  <li>10ms</li>
  </ul>
  <p>See it for yourself: <a href="http://jsfiddle.net/zryNf/" rel="noreferrer">http://jsfiddle.net/zryNf/</a></p>
  <p>So is there a more accurate way to keep time? or a way to make <code>setInterval</code> behave with more accuracy?</p>