Spread operator-head-vs-tail

Benchmark created by panzerdp on


Setup

const numbers1 = Array.from(Array(1000), (_, i) => i + 1);
  const numbers2 = Array.from(Array(10000), (_, i) => i + 1);

Test runner

Ready to run.

Testing in
TestOps/sec
[...array, item]
function appendToTail(item, array) {
  return [...array, item];
}

appendToTail(1, numbers1);
appendToTail(1, numbers2);
ready
[item, ...array]
function appendToHead(item, array) {
  return [item, ...array];
}

appendToHead(1, numbers1);
appendToHead(1, numbers2);
ready

Revisions

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

  • Revision 1: published by panzerdp on