Array.forEach vs native for

JavaScript performance comparison

Revision 6 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/mootools/1.3/mootools-yui-compressed.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var values = [];
    for (var i=0; i<10000; i++) {
    values[i] = i;
    }
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Array.forEach
var p =0;
Array.forEach(values, function (val, key) {
p++;
});
pending…
Native for
var p=0;
for (var i=0, l=values.length; i<l; i++) {
p++
}
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:

0 comments

Add a comment