我正在测量动画的性能。当我使用以下代码测量 FPS 时,它与 Chrome Frame 渲染统计不一致。let lastTime = performance.now();let lastFrameTime =
我正在测量动画的性能。当我使用以下代码测量 FPS 时,它与 Chrome Frame 渲染统计数据不一致。
let lastTime = performance.now();
let lastFrameTime = performance.now();
let frame = 0;
let fps = 0;
const loop = function () {
const now = performance.now();
const fs = now - lastFrameTime;
lastFrameTime = now;
frame++;
if (now > 1000 + lastTime) {
fps = Math.round((frame * 1000) / (now - lastTime));
frame = 0;
lastTime = now;
//If delete this statement, the stats is incorrect
el.innerText = "FPS: " + fps;
console.log(fps);
}
window.requestAnimationFrame(loop);
};
loop();
找到原因了,如果删除 el.innerText = "FPS: " + fps
,结果就不对了,点此 查看 demo。
el.innerText = "FPS: " + fps;