for vs Array.forEach vs goog.array.forEach (v16)

Revision 16 of this benchmark created on


Preparation HTML

<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>

Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
For (postfix increment)
for (var i = 0, len = arr.length; i < len; i++) {
  someFn(arr[i]);
}
 
ready
For (prefix increment)
for (var i = 0, len = arr.length; i < len; ++i) {
  someFn(arr[i]);
}
 
ready
Array.ForEach
arr.forEach(function (item){
  someFn(item);
});
ready
goog.array.forEach
goog.array.forEach(arr, function (item){
  someFn(item);
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.