shift() vs splice() vs destructuring

Benchmark created on


Setup

let arr = Array.from({
    length: 1_000
}, (_, index) => index);
let head;

Test runner

Ready to run.

Testing in
TestOps/sec
shift()
while (arr.length) {
  arr.shift();
}
ready
splice()
while (arr.length) {
  head = arr.splice(0, 1);
}
ready
destructuring
while (arr.length) {
	[head, ...arr] = arr;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.