[].forEach vs Array.prototype.forEach

Benchmark created by Jorge Chamorro on


Preparation HTML

<script>
  var o = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  var proto = Array.prototype;
  var forEach = proto.forEach;
  Object.prototype.forEach = Array.prototype.forEach;
  
  function f(v, i, o) {
   o[i] = v
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
[].forEach
[].forEach.call(o, f);
ready
Array.prototype.forEach
Array.prototype.forEach.call(o, f);
ready
proto.forEach
proto.forEach.call(o, f);
ready
forEach
forEach.call(o, f);
ready
o.forEach
o.forEach(f);
ready

Revisions

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

  • Revision 1: published by Jorge Chamorro on