Append

Benchmark created on


Setup

function appendSpread(array, value) {
  if (!array) {
    return [value];
  }
  return [...array, value];
}


function appendPush(array, value) {
  if (!array) {
    return [value];
  }
  array.push(value)
  return array;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Spread
var arr;
for (let i = 0; i < 1000; i++) {
	arr = appendSpread(arr, i);
}
console.log(arr.length)
ready
Push
var arr;
for (let i = 0; i < 1000; i++) {
	arr = appendPush(arr, i);
}
console.log(arr.length)
ready

Revisions

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