Last active
December 17, 2015 13:49
-
-
Save NikhilVerma/5620183 to your computer and use it in GitHub Desktop.
Calculate the frame rate at which the current browser is rendering the frame at
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
(function(){ | |
var TO_RUN = 20; | |
var sum = count = time = last = 0; | |
var first = false; // ignore the first time loop | |
var fn = function(){ | |
time = new Date().getTime(); | |
if(first === true){ | |
sum += time - last; | |
count++; | |
} else { | |
first = true; | |
} | |
last = time; | |
if(count < TO_RUN) { | |
requestAnimationFrame(fn); | |
} else { | |
console.log("Average Fps: " + 1000/(sum/TO_RUN)); | |
} | |
}; | |
requestAnimationFrame(fn); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment