Skip to content

Instantly share code, notes, and snippets.

@laphilosophia
Forked from capfsb/fpsMeter.js
Created December 21, 2020 18:21
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 laphilosophia/577255e7b37c55b63c6dbe7a296e06c4 to your computer and use it in GitHub Desktop.
Save laphilosophia/577255e7b37c55b63c6dbe7a296e06c4 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