Skip to content

Instantly share code, notes, and snippets.

@EchoZhaoH
Created August 19, 2021 01:14
Show Gist options
  • Save EchoZhaoH/e35429091262ea2305c16e5d3a0439c1 to your computer and use it in GitHub Desktop.
Save EchoZhaoH/e35429091262ea2305c16e5d3a0439c1 to your computer and use it in GitHub Desktop.
const rAF = function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
function (cb) {
window.setTimeout(cb, 1000 / 60);
}
}();
let frame = 0
let lastTime = Date.now();
function loop () {
const now = Date.now();
frame += 1
if (now > 1000 + lastTime) {
const fps = Math.round((frame * 1000) / (now - lastTime))
console.log(`${new Date()} 1S内 FPS:`, fps);
frame = 0
lastTime = now
}
rAF(loop)
}
loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment