Skip to content

Instantly share code, notes, and snippets.

@subzey
Created May 19, 2021 10:26
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 subzey/12b61b64221febb78763695de95a6c00 to your computer and use it in GitHub Desktop.
Save subzey/12b61b64221febb78763695de95a6c00 to your computer and use it in GitHub Desktop.
rAF fps
<!doctype html>
<html>
<head><title>rAF fps</title></head>
<body>
<output id="fps"></output>
<script>
const outputText= document.querySelector('#fps').appendChild(document.createTextNode(''));
let prev = -Infinity;
let count = 0;
requestAnimationFrame(function frame(now) {
requestAnimationFrame(frame);
const diff = now - prev;
count++;
if (diff >= 1000) {
outputText.nodeValue = (count / (now - prev) * 1000).toFixed(2);
count = 0;
prev = now;
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment