Last active
May 22, 2026 04:40
-
-
Save gkucmierz/fc357ce424bf809a3d378a3a32d83cd4 to your computer and use it in GitHub Desktop.
Run this code instantly in your browser: https://instacode.app/gist/fc357ce424bf809a3d378a3a32d83cd4
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
| const LagDetector = (() => { | |
| let run = true; | |
| const TRESHOLD = 1e3/60 + 1; // ~60 FPS | |
| let lastTime = +new Date(); | |
| (function loop() { | |
| const time = +new Date(); | |
| const diff = time - lastTime; | |
| if (diff > TRESHOLD) { | |
| console.log(`Interface blocked for ${diff}ms`); | |
| } | |
| lastTime = time; | |
| run && setTimeout(loop, 1); | |
| })(); | |
| return { stop: () => run = false }; | |
| })(); | |
| const simulateRandomLags = () => { | |
| const whenDelay = () => Math.trunc(Math.random() * 8e3); | |
| const lagDuration = () => Math.trunc(200 + Math.random() * 500); | |
| const lagLoop = () => { | |
| const t1 = Date.now(); | |
| const duration = lagDuration(); | |
| while (1) { | |
| const t2 = Date.now(); | |
| if (t2 - t1 > duration) break; | |
| } | |
| setTimeout(lagLoop, whenDelay()); | |
| }; | |
| lagLoop(); | |
| }; | |
| simulateRandomLags(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment