Last active
July 30, 2024 17:47
-
-
Save medynski/7d11fc15dc460cc68cdf2b93c4a63425 to your computer and use it in GitHub Desktop.
JavaScript FPS meter - Calculating frames per second
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.