Advertisement
falling1

fps counter

Jan 7th, 2023 (edited)
211
0
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !function() {
  2.     var times = [];
  3.     var fps;
  4.     var fpselm = document.createElement('p');
  5.     fpselm.setAttribute('style', 'all: initial; position: fixed; top: 0px; right: 0px; font-family: Arial; font-size: 20px; z-index: 2000000000; background: #ffffff80; color: black; margin: 0px; pointer-events: none');
  6.     document.body.append(fpselm);
  7.  
  8.     function loop() {
  9.         window.requestAnimationFrame(function() {
  10.             const now = performance.now();
  11.             while (times.length > 0 && times[0] <= now - 1000) {
  12.                 times.shift();
  13.             }
  14.             times.push(now);
  15.             fps = times.length;
  16.             loop();
  17.         });
  18.     };
  19.     setInterval(function() {
  20.         fpselm.innerText = `${fps} FPS`
  21.     }, 1000);
  22.  
  23.     loop();
  24. }();
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement