for vs array-foreach (v21)

Revision 21 of this benchmark created on


Setup

Array.prototype.forEach2 = function(fun) {
      var i = 0,
        len = this.length;
    
      while (i < len) {
        fun(this[i], i);
        i += 1;
      }
    
    };
    
      Array.prototype.forEach3 = function(fun) {
          var i = 0,
            len = this.length;
        
          while (i < len) {
            fun(this[i], i);
            i++;
          }
        
        };
    
    var array = Array(31).join('x').split('');
    
    function callback(value, index, object) {
      return value;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Array#forEach2
array.forEach2(callback);
ready
Array#forEach
array.forEach(callback);
ready
Array#forEach3
array.forEach3(callback);
ready

Revisions

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