Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@medynski
Last active February 2, 2024 17:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save medynski/7d11fc15dc460cc68cdf2b93c4a63425 to your computer and use it in GitHub Desktop.
Save medynski/7d11fc15dc460cc68cdf2b93c4a63425 to your computer and use it in GitHub Desktop.
JavaScript FPS meter - Calculating frames per second
function 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();
@medynski
Copy link
Author

medynski commented Feb 2, 2024

Copy and paste this script into your browser console to measure your app's frames per second (fps) for real-time performance insights and optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment