Skip to content

Instantly share code, notes, and snippets.

@arj03
Created November 3, 2021 18:24
Show Gist options
  • Save arj03/4eee4b4950916e2cd1b011f600964d3a to your computer and use it in GitHub Desktop.
Save arj03/4eee4b4950916e2cd1b011f600964d3a to your computer and use it in GitHub Desktop.
let l = []
let counter;
function setup() {
counter = 0
for (var i = 0; i < 10000; ++i) {
l.push(() => counter += 1)
}
}
setup()
console.time('shift')
while (l.length) l.shift()()
console.timeEnd('shift')
console.log(l, counter)
setup()
console.time('clear')
for (var i = 0, len = l.length; i < len; ++i)
l[i]()
l = []
console.timeEnd('clear')
console.log(l, counter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment