var fps now lastUpdate new Date var fpsFilter 50 var step function req

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
var fps = 0, now, lastUpdate = (new Date())*1 - 1;
var fpsFilter = 50;
var step = function() {
requestAnimationFrame(step);
var thisFrameFPS = 1000 / ((now=new Date()) - lastUpdate);
if (now!=lastUpdate){
fps += (thisFrameFPS - fps) / fpsFilter;
lastUpdate = now * 1 - 1;
}
}