forEach vs loop vs while (v65)

Revision 65 of this benchmark created on


Setup

var arr = [];
    for(var i = 0; i < 100000; i++) arr[i]=i;
    function nonStrictCallback(v) {v;}
    function strictCallback(v) {
      "use strict";
      v;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
arr.forEach(function(v) {v;});
ready
for loop
for(var i = 0; i < arr.length; i++){arr[i];}
ready
for loop(cached)
for(var i = 0, l = arr.length; i < l; i++){arr[i];}
ready
while
var h = 0;
while (h < arr.length) { arr[h++];};
ready
forEach cached non-strict function
arr.forEach(nonStrictCallback);
ready
forEach cached strict function
arr.forEach(strictCallback);
ready

Revisions

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