Skip to content

Instantly share code, notes, and snippets.

@waiteb3
Created January 11, 2017 23:44
Show Gist options
  • Save waiteb3/eeff151dd7f1242fb3fe75acb3bddf04 to your computer and use it in GitHub Desktop.
Save waiteb3/eeff151dd7f1242fb3fe75acb3bddf04 to your computer and use it in GitHub Desktop.
function name1() {
return 1
}
const name2 = new Function(`return function name2() {
return 1
}`)()
let start1 = 0, end1 = 0;
let start2 = 0, end2 = 0;
for (let i = 0; i < 9999; i++) {
console.error(name1())
console.error(name2())
}
start1 = Date.now()
for (let i1 = 0; i1 < 9999; i1++) {
console.error(name1())
}
end1 = Date.now()
start2 = Date.now()
for (let i2 = 0; i2 < 9999; i2++) {
console.error(name2())
}
end2 = Date.now()
console.log(end1 - start1, 'ms')
console.log(end2 - start2, 'ms')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment