Array Concat Push ForEach Allocate

Benchmark created on


Setup

var array1 = array2 = [];
  
  for (var i=0; i< 100; i++) {
      array1.push(i); 
  }
  
  for (var i=0; i< 100; i++) {
      array2.push(i); 
  }

Test runner

Ready to run.

Testing in
TestOps/sec
array prototype push
[].push.apply(array1, array2);
ready
concat
array1.concat(array2);
ready
forEach push
array2.forEach(function(value) {
    array1.push(value);
});
ready
length forEach push
var length1 = array1.length,
    length2 = array2.length;

array1.length = length1 + length2 + 1;


array2.forEach(function(value, index) {
    array1[length1 + index] = value;
});
ready

Revisions

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