Arrays jQuery.merge vs concat

JavaScript performance comparison

Revision 3 of this test case created

Info

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 code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  //unmodified array
  var baseArray = ["Napoleon"];
 
  //modified arrays
  var catArray = [],
      merArray = [];
 
  //cache concat prototype for best performance
  var concat = Array.prototype.concat;
</script>

Preparation code output

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
catArray = concat.call(catArray, baseArray);
pending…
merge
$.merge(merArray, baseArray);
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