Skip to content

Instantly share code, notes, and snippets.

@milksense
Last active October 26, 2021 02:16
Show Gist options
  • Save milksense/85dc518844a720109cf697196bc5daa4 to your computer and use it in GitHub Desktop.
Save milksense/85dc518844a720109cf697196bc5daa4 to your computer and use it in GitHub Desktop.
Get current FPS via TS
"use strict";
let fps = 1;
let times = [];
const debug = true;
const fpsLoop = (timestamp = 0, debug) => {
while (times.length > 0 && times[0] <= timestamp - 1000) {
times.shift();
}
times.push(timestamp);
fps = times.length;
if (debug) {
console.log(fps);
}
requestAnimationFrame(fpsLoop);
};
requestAnimationFrame(fpsLoop);
let fps: number = 1;
let times: any[] = [];
const debug: boolean = true;
const fpsLoop = (timestamp: number = 0, debug?: number | undefined) => {
while (times.length > 0 && times[0] <= timestamp - 1000) {
times.shift();
}
times.push(timestamp);
fps = times.length;
if (debug) {
console.log(fps);
}
requestAnimationFrame(fpsLoop);
}
requestAnimationFrame(fpsLoop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment