Javascript array concat vs push (v49)

Revision 49 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
arr2.concat(arr1);
ready
push dynamic
var arr1Length = arr1.length;
for (j = 0; j < arr1Length; ++j)
  arr2.push(arr1[j]);
ready
push static
arr2.push(arr1[0]);
arr2.push(arr1[1]);
arr2.push(arr1[2]);
arr2.push(arr1[3]);
arr2.push(arr1[4]);
ready
assignment
arr2[0] = arr1[0];
arr2[1] = arr1[1];
arr2[2] = arr1[2];
arr2[3] = arr1[3];
arr2[4] = arr1[4];
ready

Revisions

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