Created
August 19, 2021 01:14
-
-
Save EchoZhaoH/e35429091262ea2305c16e5d3a0439c1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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