array push (v3)

Revision 3 of this benchmark created on


Setup

function appendToArray1(arr, add){
  const addSize = add.length;
  if (addSize === 0) {
    return;
  }
  const baseSize = arr.length;
  arr.length = baseSize + addSize;

  for (let i = 0; i < addSize; i++) {
    arr[baseSize + i] = add[i];
  }
}
function appendToArray2(arr, add){
  const addSize = add.length;
  if (addSize === 0) {
    return;
  }
  const baseSize = arr.length;
  arr.length = baseSize + addSize;

  for (let i = 0; i < addSize; i++) {
  	const element = arr[i]
    arr[baseSize + i] = element;
  }
}
const ar = Array.from(Array(1000).keys())
const add = Array.from(Array(20000).keys())

Test runner

Ready to run.

Testing in
TestOps/sec
appendToArray1
appendToArray1(ar,add)
ready
appendToArray2
appendToArray2(ar,add)
ready

Revisions

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