Array.forEach vs native for

JavaScript performance comparison

Revision 8 of this test case created by Benjamin

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] = {'value':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
Array.forEach(values, function (val, key) {});
pending…
Native for
for (var i=0, l=values.length; i<l; i++) {}
pending…
w/o caching values.length
for (var i=0; i<values.length; i++) {}
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