forEach vs loop vs while

JavaScript performance comparison

Revision 71 of this test case created by muffin

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  for(var i = 0; i < 1000; i++) arr[i]=i;

};
</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
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…
while
var h = 0;
while (h < arr.length) { arr[h++];};
pending…
for loop (external cache)
var i = 0, l = arr.length;
for(; 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