concat vs push.apply (v20)

Revision 20 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var sampleA = [],
        sampleB = [],
        sampleC = [],
        sampleD = [],
        core_push = Array.prototype.push;
    
    for (var i = 0; i < 42; ++i) {
      sampleA[i] = {v : i*2}; //i*2
      sampleB[i] = {v : i*3}; //i*3
      sampleC[i] = {v : i*4}; //i*4
      sampleD[i] = {v : i*5}; //i*5  
    }

Test runner

Ready to run.

Testing in
TestOps/sec
concat
var cloneA = sampleA.slice(0);
var cloneB = sampleB.slice(0);
var cloneC = sampleC.slice(0);
var cloneD = sampleD.slice(0);

cloneA = cloneA.concat(cloneB);
cloneA = cloneA.concat(cloneC);
cloneA = cloneA.concat(cloneD);
ready
push.apply
var cloneA = sampleA.slice(0);
var cloneB = sampleB.slice(0);
var cloneC = sampleC.slice(0);
var cloneD = sampleD.slice(0);

cloneA.push.apply(cloneA, cloneB);
cloneA.push.apply(cloneA, cloneC);
cloneA.push.apply(cloneA, cloneD);
ready
Array#push.apply
var cloneA = sampleA.slice(0);
var cloneB = sampleB.slice(0);
var cloneC = sampleC.slice(0);
var cloneD = sampleD.slice(0);

Array.prototype.push.apply(cloneA, cloneB);
Array.prototype.push.apply(cloneA, cloneC);
Array.prototype.push.apply(cloneA, cloneD);
ready
core_push.apply
var cloneA = sampleA.slice(0);
var cloneB = sampleB.slice(0);
var cloneC = sampleC.slice(0);
var cloneD = sampleD.slice(0);

core_push.apply(cloneA, cloneB);
core_push.apply(cloneA, cloneC);
core_push.apply(cloneA, cloneD);
ready
$.extend
var cloneA = sampleA.slice(0);
var cloneB = sampleB.slice(0);
var cloneC = sampleC.slice(0);
var cloneD = sampleD.slice(0);

$.extend(cloneA, cloneB, cloneC, cloneD  );
ready

Revisions

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