Skip to content

Instantly share code, notes, and snippets.

@NikhilVerma
Last active December 17, 2015 13:49
Show Gist options
  • Save NikhilVerma/5620183 to your computer and use it in GitHub Desktop.
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
(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