Skip to content

Instantly share code, notes, and snippets.

@davedx
Created April 2, 2014 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davedx/9929388 to your computer and use it in GitHub Desktop.
Save davedx/9929388 to your computer and use it in GitHub Desktop.
Display FPS using requestAnimationFrame
var lastCalledTime;
var fps;
function requestAnimFrame(t) {
if(!lastCalledTime) {
lastCalledTime = new Date().getTime();
fps = 0;
} else {
delta = (t - lastCalledTime)/1000;
lastCalledTime = t;
fps = parseInt(1/delta);
$('#someDivElement').html(fps + ' fps');
}
window.requestAnimationFrame(requestAnimFrame);
}
requestAnimFrame(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment