Skip to content

Instantly share code, notes, and snippets.

@8bitDesigner
Created December 17, 2012 21:59
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 8bitDesigner/4322702 to your computer and use it in GitHub Desktop.
Save 8bitDesigner/4322702 to your computer and use it in GitHub Desktop.
Using underscore to make sense of `window.performance.timing`
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)
@8bitDesigner
Copy link
Author

Output:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment