I'm using delta times to measure how much time has passed between frames in my loop. The value of the time variable is used as a multiplier for animation speeds. This makes sure that a user who has a 60 Hz display will experience the same animation speed as a user with a 144 Hz display (albeit at different frame rates). Without this multiplier, the 144 Hz user would experience animations that are way faster than the person with a 60 Hz display. This is how I achieve this:
let time;
let last = window.performance.now();
function loop(current) {
time = current - last;
last = current;
// run game logic and render
requestAnimationFrame(loop);
}
Even though this measurement works great, it also has its flaws. Browsers aren't as consistent as native apps and the time variable's value will vary greatly during stutters, resulting in "jumpy" animations.
Are there any better ways to detect a browser's frame rate without relying on requestAnimationFrame's inconsistent numbers?