Native map vs. forEach appending vs. array looping

JavaScript performance comparison

Test case created by Long Ouyang

Preparation code

<script>
  var g = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27];
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Map (native)
var h = g.map(function(x) {
 return x + 2
});
pending…
forEach (native)
var h = [];
g.forEach(function(x) {
 h.push(x + 2);
})
pending…
Loop
var h = [];
for (var i = 0, len = g.length; i < len; i++) {
 h.push(g[i] + 2);
}
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.

0 Comments