forEach vs loop vs while (v66)

Revision 66 of this benchmark created on


Setup

var arr = [];
    for(var i = 0; i < 1000000; 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
While --
var l = arr.length;
while (l > 0) { arr[--l];};
ready
While if
var l = arr.length;
while (1) { if(l>0){ arr[--l]; } else { break } };
ready

Revisions

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