Skip to content

Instantly share code, notes, and snippets.

@cdaringe
Created January 23, 2017 17:16
Show Gist options
  • Save cdaringe/0a594dedeee2832fd2f922fee2861502 to your computer and use it in GitHub Desktop.
Save cdaringe/0a594dedeee2832fd2f922fee2861502 to your computer and use it in GitHub Desktop.
nested-vs-inline-fns
var ITCOUNT = 1e6
function a () {
return function b (z) { return z + 1 }
}
var sum1 = 0
for (var i = 0; i < ITCOUNT; ++i) {
var toAdd1 = Math.random()
var start1 = process.hrtime()[1]
a()(toAdd1)
sum1 += process.hrtime()[1] - start1
}
function b (z) {
return z + 1
}
function a () {
return b
}
var sum2 = 0
for (var i=0; i < ITCOUNT; ++i) {
var toAdd2 = Math.random()
var start2 = process.hrtime()[1]
a()(toAdd2)
sum2 += process.hrtime()[1] - start2
}
console.log(`results: nested takes ${((sum1 - sum2) / sum2).toFixed(3)}% longer than inline`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment