array-concat-vs-custom

JavaScript performance comparison

Test case created by John-David Dalton and last updated

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function concatList(list, otherList) {
      var pad = list.length, length = otherList.length;
      while (length--) list[pad + length] = otherList[length];
      return list;
    }
   
    function nativeConcat(list, otherList) {
      return list.concat(otherList);
    }
   
    var array2 = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
};
</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
native concat
var array1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
var r = nativeConcat(array1, array2)[15];
pending…
custom
var array1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
var r = concatList(array1, array2)[15];
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