Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Last active May 22, 2026 04:40
Show Gist options
  • Select an option

  • Save gkucmierz/fc357ce424bf809a3d378a3a32d83cd4 to your computer and use it in GitHub Desktop.

Select an option

Save gkucmierz/fc357ce424bf809a3d378a3a32d83cd4 to your computer and use it in GitHub Desktop.
Run this code instantly in your browser: https://instacode.app/gist/fc357ce424bf809a3d378a3a32d83cd4
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