concat vs push.apply (v19)

Revision 19 of this benchmark created by Kevin Ennis on


Preparation HTML

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

Setup

var sampleA = [],
        sampleB = [],
        core_push = Array.prototype.push;
    
    for (var i = 0; i < 42; ++i) {
      sampleA[i] = {};
      sampleB[i] = {};
    }

Test runner

Ready to run.

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

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

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

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

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

$.extend(cloneA, cloneB);
ready

Revisions

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