My each vs native forEach

Benchmark created by Matthew on


Preparation HTML

<script>
  Array.prototype.each = function(fn) {
   var i, l, v;
  
   //if (Object.prototype.toString.call(fn) === "[object Function]") {
   for (i = 0, l = this.length; i < l; i++) {
    fn.call(this[i], i, this[i]);
   }
   //}
   return this;
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
My each
['a', 'b', 'c'].each(function() {
 var i = 2 + 2;
});
ready
Native forEach
['a', 'b', 'c'].forEach(function() {
 var i = 2 + 2;
});
ready

Revisions

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