Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created October 7, 2019 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/99773cc8edc4115e6ba156a503dd2c41 to your computer and use it in GitHub Desktop.
Save nolanlawson/99773cc8edc4115e6ba156a503dd2c41 to your computer and use it in GitHub Desktop.
Test rAF timing
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Test rAF timing</title>
</head>
<body>
<h1>Test rAF timing</h1>
<pre id="display"></pre>
<script>
window.addEventListener('load', function () {
var timestamps = []
function onRaf (ts) {
timestamps.push(ts)
if (timestamps.length < 30) {
requestAnimationFrame(onRaf)
} else {
showResults()
}
}
function showResults () {
var display = document.getElementById('display')
for (var i = 0; i < timestamps.length; i++) {
display.innerHTML += timestamps[i] +
(i > 0 ? (' (+' + (timestamps[i] - timestamps[i - 1]) + ')') : '') +
'\n'
}
}
requestAnimationFrame(onRaf)
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment