Map vs. Not
JavaScript performance comparison
Info
Simple comparison of using a for loop to extract values from an object into two arrays vs using two map calls (and a forEach).
Preparation code
<script>
Benchmark.prototype.setup = function() {
var friends = [];
var totalFriends = 10000;
for (var i = 0; i < totalFriends; i++) {
friends.push({
name: 'friendly' + i.toString(), id: i
});
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Map |
|
pending… |
Loop |
|
pending… |
Loop, size predeclared |
|
pending… |
forEach |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments