concat-array (v2)

Revision 2 of this benchmark created on


Description

Different methods of concatenating two arrays with 500 numbers. The first test uses the simple concat method, which creates a new array; the rest operate on the existing array.

Switched the order around, to confirm that the variable in the setup code was actually being created locally to each test.

Setup

var mainArr = [];
  for (var i=0;i<500;i++) {
    mainArr.push(Math.random());
  }
  var arrToAppend = mainArr.slice(0);

  Benchmark.prototype.setup = function() {
    var combinedArr = mainArr.slice(0);
  };

Test runner

Ready to run.

Testing in
TestOps/sec
push existing
Array.prototype.push.apply(combinedArr, arrToAppend);
ready
splice existing
Array.prototype.splice.apply(combinedArr, [combinedArr.length, 0].concat(arrToAppend));
ready
unshift existing
Array.prototype.unshift.apply(combinedArr, arrToAppend);
ready
concat new
combinedArr = combinedArr.concat(arrToAppend);
ready

Revisions

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