Created
January 18, 2015 19:52
-
-
Save digitalicarus/b9cc460d418c3d7b5d06 to your computer and use it in GitHub Desktop.
average frame time
This file contains 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
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