Created
October 7, 2019 21:20
-
-
Save nolanlawson/99773cc8edc4115e6ba156a503dd2c41 to your computer and use it in GitHub Desktop.
Test rAF timing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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