Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ee292b8a74
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (90 sloc) 3.022 kb
<html>
<head>
<style>
body {
font-family: sans-serif;
}
#res {
background: lightgray;
}
div.skew {
color: red;
}
</style>
<script>
var interval = null;
var repetitions;
var repeatExpectedDuration;
var repeatStartTime;
var repeatPrevTime;
var outString = "";
var phase;
function start() {
phase = 0;
outString = "<pre>";
setTimeout(next, 2000);
}
function next() {
++phase;
if (phase == 1) {
outString += "10 repetitions of SetInterval at 10 ms spacing<br>";
repeat(sample, 10, 10);
} else if (phase == 2) {
outString += "10 repetitions of SetInterval at 1 ms spacing<br>";
repeat(sample, 10, 1);
} else if (phase == 3) {
outString += "10 repetitions of SetInterval at 3 ms spacing<br>";
repeat(sample, 10, 3);
} else if (phase == 4) {
outString += "10 repetitions of SetInterval at 7 ms spacing<br>";
repeat(sample, 10, 7);
} else if (phase == 5) {
outString += "20 repetitions of SetInterval at 16.66 ms spacing<br>";
repeat(sample, 20, 16.66);
} else if (phase == 6) {
outString += "5 repetitions of SetInterval at 20 ms spacing<br>";
repeat(sample, 5, 20);
} else if (phase == 7) {
outString += "5 repetitions of SetInterval at 25 ms spacing<br>";
repeat(sample, 5, 25);
} else if (phase == 8) {
outString += "5 repetitions of SetInterval at 100 ms spacing<br>";
repeat(sample, 5, 100);
} else if (phase == 9) {
outString += "</pre>";
document.getElementById("res").innerHTML = outString;
}
}
function repeat(fun, count, time) {
repetitions = count;
repeatExpectedDuration = count * time;
repeatStartTime = (new Date).getTime();
repeatPrevTime = repeatStartTime;
interval = setInterval(fun, time);
}
function decRepeat() {
if (--repetitions <= 0) {
clearInterval(interval);
var overrun = 100 * ((new Date).getTime() - repeatStartTime - repeatExpectedDuration) / repeatExpectedDuration;
if (overrun > 10) {
outString += "<div class='skew'> "+Math.round(overrun)+"% over time</div>";
}
repetitions = 0;
outString += /*"waiting 500ms"*/"<br>";
setTimeout(next, 500);
}
}
function sample() {
var time = (new Date).getTime();
outString += " rel: "+(time-repeatStartTime)+" ms, delta: "+(time - repeatPrevTime)+" ms<br>";
repeatPrevTime = time;
decRepeat();
}
</script>
</head>
<body onload="start()">
<div>Testing your browser's timer granularity. Results will be visible at the end. Please wait 10 seconds.</div>
<div id="res"></div>
<hr noshade="true" size="1">
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.