Created
March 2, 2021 17:35
-
-
Save p-pavel/cd32c410fa4c2d0511e5415673495376 to your computer and use it in GitHub Desktop.
This file contains 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
<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