forEach vs loop vs while

JavaScript performance comparison

Revision 66 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  for(var i = 0; i < 1000000; i++) arr[i]=i;
  function nonStrictCallback(v) {v;}
  function strictCallback(v) {

    "use strict";
    v;
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
while
var h = 0;
while (h < arr.length) { arr[++h];};
pending…
While --
var l = arr.length;
while (l > 0) { arr[--l];};
pending…
While if
var l = arr.length;
while (1) { if(l>0){ arr[--l]; } else { break } };
pending…
forEach
arr.forEach(function(v) {v;});
pending…
for loop
for(var i = 0; i < arr.length; i++){arr[i];}
pending…
for loop(cached)
for(var i = 0, l = arr.length; i < l; i++){arr[i];}
pending…

Compare results of other browsers

Revisions

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

0 Comments