Created
February 3, 2022 17:45
-
-
Save vertexvaar/76b2bbcc37eb61fdfd52ac1969730931 to your computer and use it in GitHub Desktop.
Count Browser Window Framerate with JavaScript
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
let previousTimeStamp = null, frames = 0; | |
function counter(timestamp) { | |
if (previousTimeStamp == null) { | |
previousTimeStamp = parseInt(timestamp / 1000); | |
} | |
frames = frames + 1; | |
const sec = parseInt(timestamp / 1000); | |
if (sec !== previousTimeStamp) { | |
previousTimeStamp = sec; | |
console.log(frames); | |
frames = 0; | |
} | |
window.requestAnimationFrame(counter); | |
} | |
window.requestAnimationFrame(counter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment