for vs Array.forEach vs goog.array.forEach

JavaScript performance comparison

Revision 16 of this test case created by

Preparation code

<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js">
</script>
<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/array/array.js">
</script>

      
<script>
Benchmark.prototype.setup = function() {
    // Populate the base array
    var arr = [];
    for (var i = 0; i < 100; i++) {
      arr[i] = i;
    }
  
    function someFn(i) {
      return Math.exp(i * 2);
    }

};
</script>

Preparation code output

<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/array/array.js"> </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
For (prefix increment)
for (var i = 0, len = arr.length; i < len; ++i) {
  someFn(arr[i]);
}
pending…
For (postfix increment)
for (var i = 0, len = arr.length; i < len; i++) {
  someFn(arr[i]);
}
pending…
Array.ForEach
arr.forEach(function (item){
  someFn(item);
});
pending…
goog.array.forEach
goog.array.forEach(arr, function (item){
  someFn(item);
});
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