Skip to content

Instantly share code, notes, and snippets.

@p-pavel
Created March 2, 2021 17:35
Show Gist options
  • Save p-pavel/cd32c410fa4c2d0511e5415673495376 to your computer and use it in GitHub Desktop.
Save p-pavel/cd32c410fa4c2d0511e5415673495376 to your computer and use it in GitHub Desktop.
<html>
<head>
<script>
let counter = 0;
let lastCounter = counter;
let lastTime = Date.now();
function showFPS() {
const elem = document.getElementById("FPS");
const currentTime = Date.now();
const currentCounter = counter;
elem.innerText = 1000 * (currentCounter - lastCounter) / (currentTime - lastTime);
lastCounter = currentCounter;
lastTime = currentTime;
}
function setUp() {
window.setInterval(showFPS,1000);
update();
}
function update() {
const elem = document.getElementById("counter");
elem.innerText = ++counter;
window.requestAnimationFrame(update);
}
</script>
</head>
<body onload="setUp()">
<p>Testing browser update performance. Below there's a counter to make browser really update screen (unlike FE)</p>
<p id="counter"></p>
<p>Here's FPS counter:</p>
<p id="FPS">Not available</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment