Skip to content

Instantly share code, notes, and snippets.

@digitalicarus
Created January 18, 2015 19:52
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 digitalicarus/b9cc460d418c3d7b5d06 to your computer and use it in GitHub Desktop.
Save digitalicarus/b9cc460d418c3d7b5d06 to your computer and use it in GitHub Desktop.
average frame time
function flashFrameTime (counts, cb) {
if (!typeof counts === 'number' || !counts > 0) { throw "no!"; }
var accum = []
, reqFrame = window.requestAnimationFrame
;
function calcFramerate () {
return accum
.slice(0, accum.length-1)
.map(function (v, i) {
return accum[i+1] - v;
})
.reduce(function (prev, curr) {
return prev + curr;
}) / (accum.length - 1);
}
(function accumulate () {
if (counts-- > 0) {
accum.push(Date.now());
reqFrame(accumulate);
} else {
cb && cb(calcFramerate());
}
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment