concat vs push.apply

JavaScript performance comparison

Revision 17 of this test case created by Krinkle

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var sampleA = [],
        sampleB = [],
        core_push = Array.prototype.push;
   
    for (var i = 0; i < 42; ++i) {
      sampleA[i] = {};
      sampleB[i] = {};
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
concat
sampleA = sampleA.concat(sampleB);
pending…
push.apply
sampleA.push.apply(sampleA, sampleB);
pending…
Array#push.apply
Array.prototype.push.apply(sampleA, sampleB);
pending…
core_push.apply
core_push.apply(sampleA, sampleB);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment