concat vs merge vs push
JavaScript performance comparison
Info
Take an object array add a new member to each entry.
Comparison * concat -> update + map * merge -> update + map * each -> update + push * each -> push + update * for loop -> update + push
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//raw.github.com/documentcloud/underscore/master/underscore.js"></script>
<script>
Benchmark.prototype.setup = function() {
var baseArray = [
{name: "foo"},
{name: "bar"},
{name: "baz"}
];
//modified arrays
var catArray = merArray = pushArray = [];
// Caches
var x, _i, _len;
};
</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… |
Update then push |
|
pending… |
Push, then update |
|
pending… |
For loop, update then push |
|
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 leeroy
- Revision 2: published by Xav
0 comments