.unshift() vs .push()+.reverse()

Benchmark created on


Setup

const SIZE = 10_000;

Test runner

Ready to run.

Testing in
TestOps/sec
.unshift()
const arr = [];

for (let i = 0; i < SIZE; i++) {
  arr.unshift(i);
}
ready
.push() + .toReversed()
const arr = [];

for (let i = 0; i < SIZE; i++) {
  arr.push(i);
}

const reversed = arr.toReversed();
ready
.push() + .reverse()
const arr = [];

for (let i = 0; i < SIZE; i++) {
  arr.push(i);
}

const reversed = arr.reverse();
ready

Revisions

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