统计 FPS
本文最后更新于:2023年3月19日 晚上
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| let count = 0; let prevTimestamp;
function showFPS(fps) { console.log(fps); }
function loop(timestamp) { if (prevTimestamp) { count++; if (timestamp - prevTimestamp >= 1000) { showFPS(Math.round((count * 1000) / (timestamp - prevTimestamp))); prevTimestamp = timestamp; count = 0; } } else { prevTimestamp = timestamp; } window.requestAnimationFrame(loop); }
window.requestAnimationFrame(loop);
|