Arrays jQuery.merge vs concat (v5)

Revision 5 of this benchmark created by leeroy 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 = pushArray = [];
  
  //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
push
for(elem in baseArray)
{
  pushArray.push(elem);
}
ready

Revisions

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