Created
December 17, 2012 21:59
-
-
Save 8bitDesigner/4322702 to your computer and use it in GitHub Desktop.
Using underscore to make sense of `window.performance.timing`
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
function pairs(value, key) { | |
return [value, key] | |
} | |
function nonZero(array) { | |
return array[0] !== 0 | |
} | |
function relativeTime(item, index, list) { | |
var time = item[0] | |
, name = item[1] | |
time = (time - list[0][0]) / 1000 | |
return [time, name] | |
} | |
function log(item, index, list) { | |
console.log(item[0], item[1]) | |
} | |
_.chain(window.performance.timing).map(pairs).sort().filter(nonZero).map(relativeTime).map(log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: