Skip to content

Instantly share code, notes, and snippets.

@magjac
Last active August 3, 2017 21:48
Show Gist options
  • Save magjac/073cbfc7c15c0b0aa56c684e1f5d69ff to your computer and use it in GitHub Desktop.
Save magjac/073cbfc7c15c0b0aa56c684e1f5d69ff to your computer and use it in GitHub Desktop.
D3 timer bug (?) 1
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<h1>Open the console and look for messages</h1>
<script src="//d3js.org/d3.v4.min.js"></script>
<script>
var period = 1000;
var i1 = d3.interval(f1, period);
var n = 1;
var m = 100000000;
var t0 = t1 = Date.now();
function f1(elapsed) {
var now = Date.now()
console.log('f1 now =', now, 'elapsed =', elapsed, 'real elapsed =', now - t0, 'elapsed error =', now - t0 - elapsed, 'interval error =', now - t1 - period);
console.time('f1 ' + n);
for (i = 0; i < n; i++)
;
console.timeEnd('f1 ' + n);
t1 = now;
n = m;
m = m / 10;
if (n < 1) {
i1.stop();
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment