-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfps.js
More file actions
28 lines (22 loc) · 706 Bytes
/
fps.js
File metadata and controls
28 lines (22 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Get the DOM element for displaying FPS
const fpsDiv = document.getElementById('fpsValue');
let frames = 0;
let startTime = performance.now();
let FPSNormal = 0;
// Function to calculate and update the FPS
const calculateFPSNormal = () => {
const t = performance.now();
const dt = t - startTime;
if (dt > 1000) {
FPSNormal = (frames * 1000) / dt;
frames = 0;
startTime = t;
}
frames++;
};
// Function to update the displayed FPS
const updateLabel = (fps) => {
fpsDiv.textContent = Math.round(fps);
};
// Call the calculateFPSNormal function periodically (e.g., in your animation loop)
// and then call updateLabel to update the displayed FPS