Skip to content

Instantly share code, notes, and snippets.

@vertexvaar
Created February 3, 2022 17:45
Show Gist options
  • Save vertexvaar/76b2bbcc37eb61fdfd52ac1969730931 to your computer and use it in GitHub Desktop.
Save vertexvaar/76b2bbcc37eb61fdfd52ac1969730931 to your computer and use it in GitHub Desktop.
Count Browser Window Framerate with JavaScript
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