Created
April 2, 2014 07:22
-
-
Save davedx/9929388 to your computer and use it in GitHub Desktop.
Display FPS using requestAnimationFrame
This file contains hidden or 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
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