Created
May 19, 2021 10:26
-
-
Save subzey/12b61b64221febb78763695de95a6c00 to your computer and use it in GitHub Desktop.
rAF fps
This file contains hidden or 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> | |
<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