Fast Array Foreach (v3)

Revision 3 of this benchmark created by foobar on


Setup

// Populate the base array
      var arr = [];
      for (var i = 0; i < 1000; i++) {
        arr[i] = i;
      }
    
      function someFn(i) {
        return i * 3 * 8;
      }
    
    function each(fn, context){
          var self = this
            , index = 0
            , length = self.length
    
          for(;index < length; index++) fn.call(context, self[index], index, self)
    
          return self
        }
    
    Array.prototype.each = each

Test runner

Ready to run.

Testing in
TestOps/sec
Array.ForEach
arr.forEach(someFn)
ready
For
for (var i = 0, len = arr.length; i < len; i++) {
  someFn(arr[i]);
}
ready
each
arr.each(someFn)
ready

Revisions

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