For Loop vs. Optimized For Loop

JavaScript performance comparison

Revision 7 of this test case created by

Preparation code

<a href="#">Test</a>
<a href="#">Test</a>
<a href="#">Test</a>
<a href="#">Test</a>
<a href="#">Test</a>
<a href="#">Test</a>
<a href="#">Test</a>
<a href="#">Test</a>
<a href="#">Test</a>
<a href="#">Test</a>
    

Preparation code output

<a href="#">Test</a> <a href="#">Test</a> <a href="#">Test</a> <a href="#">Test</a> <a href="#">Test</a> <a href="#">Test</a> <a href="#">Test</a> <a href="#">Test</a> <a href="#">Test</a> <a href="#">Test</a>

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
Customary For Loop
var anchors = document.getElementsByTagName("a");

for (var i = 0; i < anchors.length; i++) {
  anchors[i].style.color = "red";
}
pending…
Optimized For Loop
var anchors = document.getElementsByTagName("a");

for (var i = anchors.length - 1; i >= 0; i -= 1) {
  anchors[i].style.color = "red";
}
pending…
for in loop
var anchors = document.getElementsByTagName("a");

for (x in anchors) {
  anchors[x].style.color = "red";
}
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

Test Test Test Test Test Test Test Test Test Test