whisper.cat/weboasis/todo/scripts/AppFps.js

41 lines
708 B
JavaScript
Raw Normal View History

2023-10-05 23:28:32 +11:00
/* global VT */
window.VT = window.VT || {};
VT.AppFps = function (el) {
var sampleSize = 20;
var times = [];
tick();
function tick() {
requestAnimationFrame(tick);
times.push(performance.now());
if (times.length <= sampleSize) return;
var min = Infinity;
var max = 0;
var sum = 0;
for (var i = 1; i < sampleSize + 1; ++i) {
var delta = times[i] - times[i - 1];
min = Math.min(min, delta);
max = Math.max(max, delta);
sum += delta;
}
var fps = (sampleSize / sum) * 1000;
el.innerText =
fps.toFixed(0) +
' fps (' +
min.toFixed(0) +
' ms - ' +
max.toFixed(0) +
' ms)';
times = [];
}
};