Skip to content

Instantly share code, notes, and snippets.

@capfsb
Forked from medynski/fpsMeter.js
Created April 17, 2017 23:41
Show Gist options
  • Save capfsb/3fd1b700b4732debb29aefd576cf54ef to your computer and use it in GitHub Desktop.
Save capfsb/3fd1b700b4732debb29aefd576cf54ef 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