concat vs push.apply
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var sampleA = [],
sampleB = [],
core_push = Array.prototype.push;
for (var i = 0; i < 42; ++i) {
sampleA[i] = {};
sampleB[i] = {};
}
};
</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… |
push.apply |
|
pending… |
Array#push.apply |
|
pending… |
core_push.apply |
|
pending… |
$.extend |
|
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 2: published by satyr
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published by Nebojsa Sabovic
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published
- Revision 17: published by Krinkle
- Revision 18: published by 54yuri
- Revision 19: published by Kevin Ennis
- Revision 20: published
- Revision 21: published by 54yuri
- Revision 22: published by 54yuri
- Revision 23: published by 54yuri
- Revision 24: published
- Revision 25: published
1 comment
The older versions of this test were actually mutating the original sampleA and sampleB arrays when they ran - which totally invalidates the results.