Skip to content

Instantly share code, notes, and snippets.

@juji
Forked from capfsb/fpsMeter.js
Created December 12, 2023 21:09
Show Gist options
  • Save juji/fd22558d510ad87fb1cad9810f294ffd to your computer and use it in GitHub Desktop.
Save juji/fd22558d510ad87fb1cad9810f294ffd to your computer and use it in GitHub Desktop.
JavaScript FPS meter - Calculating frames per second
fpsMeter() {
let prevTime = Date.now(),
frames = 0;
requestAnimationFrame(function loop() {
const time = Date.now();
frames++;
if (time > prevTime + 1000) {
let fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) );
prevTime = time;
frames = 0;
console.info('FPS: ', fps);
}
requestAnimationFrame(loop);
});
}
fpsMeter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment