Last active
October 26, 2021 02:16
-
-
Save milksense/85dc518844a720109cf697196bc5daa4 to your computer and use it in GitHub Desktop.
Get current FPS via TS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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