Arrays jQuery.merge vs concat (v3)

Revision 3 of this benchmark created 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>
<script>
  //unmodified array
  var baseArray = ["Napoleon"];
  
  //modified arrays
  var catArray = [],
      merArray = [];
  
  //cache concat prototype for best performance
  var concat = Array.prototype.concat;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
concat
catArray = concat.call(catArray, baseArray);
ready
merge
$.merge(merArray, baseArray);
ready

Revisions

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