Javascript array concat vs push (v47)

Revision 47 of this benchmark created on


Description

for extreme cases to use in image data in canvas

Setup

var arr1 = [0, 1, 2, 3, 4];
    
    var arr2 = [];
    
    var i = 0;
    
    var j = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
concat
for (i = 1000; i > 0; i--) {
  arr2.concat(arr1);
}
ready
push dynamic
var arr1Length = arr1.length
for (i = 1000; i > 0; i--) {
  for (j = 0; j < arr1Length; j++) {
    arr1.push(arr2[j]);
  }
}
ready
push static
for (i = 1000; i > 0; i--) {
  arr1.push(arr2[0]);
  arr1.push(arr2[1]);
  arr1.push(arr2[2]);
  arr1.push(arr2[3]);
  arr1.push(arr2[4]);

}
ready
asignment
for (i = 1000; i > 0; i--) {
  arr1[i] = arr2[0];
  arr1[i + 1] = arr2[1];
  arr1[i + 2] = arr2[2];
  arr1[i + 3] = arr2[3];
  arr1[i + 4] = arr2[4];
}
ready

Revisions

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