Arrays jQuery.merge vs concat (v4)

Revision 4 of this benchmark created by Xav on


Description

Merge creates a smaller footprint because it loops through the original array and adds the new items. Concat is a built-in Javascript function and should be faster, but has a larger footprint.

Preparation HTML

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

Setup

//unmodified array
    var baseArray = ["Napoleon", "Bonaparte", "was", "exiled", "to", "the", "island", "of", "elba", "in", "1813"];
      
    //modified arrays
    var catArray = [],
        merArray = [],
        forArray = []
    
    var x, _i, _len;

Test runner

Ready to run.

Testing in
TestOps/sec
concat
catArray = catArray.concat(baseArray);
ready
merge
$.merge(merArray, baseArray);
ready
Coffeescript list comprehension push
for (_i = 0, _len = baseArray.length; _i < _len; _i++) {
  x = baseArray[_i];
  forArray.push(x);
}
ready

Revisions

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