Arrays jQuery.merge vs concat
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
concat |
|
pending… |
merge |
|
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:
- Revision 1: published by Jeremy Mullinax-Hill
- Revision 2: published
- Revision 3: published
- Revision 4: published by Xav
- Revision 5: published by leeroy
0 comments