Looping Test

JavaScript performance comparison

Revision 4 of this test case created by Chris

Preparation code

<a href="#" title="link1">link1</a>
<a href="#" title="link2">link2</a>
<a href="#" title="link3">link3</a>
<a href="#" title="link4">link4</a>
<a href="#" title="link5">link5</a>
<a href="#" title="link6">link6</a>
<a href="#" title="link7">link7</a>
<a href="#" title="link8">link8</a>
<a href="#" title="link9">link9</a>
<a href="#" title="link10">link10</a>
<a href="#" title="link11">link11</a>
<a href="#" title="link12">link12</a>
<a href="#" title="link13">link13</a>
<a href="#" title="link14">link14</a>
<a href="#" title="link15">link15</a>
<a href="#" title="link16">link16</a>
<a href="#" title="link17">link17</a>
<a href="#" title="link18">link18</a>
<a href="#" title="link19">link19</a>
<a href="#" title="link20">link20</a>
<a href="#" title="link21">link21</a>
<a href="#" title="link22">link22</a>
<a href="#" title="link23">link23</a>
<a href="#" title="link24">link24</a>
<a href="#" title="link25">link25</a>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Normal Loop
for (var i = 0; i < document.links.length; i++) {
    console.log(document.links[i]);
}
 
pending…
Optimized Loop 1
for (var i = 0, j = document.links.length; i < j ; i++) {
    console.log(document.links[i]);
}
pending…
Optimized Loop 2
for (var i = 0, j = document.links, k = j.length; i < k ; i++) {
    console.log(j[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. Here’s a list of current revisions for this page:

0 comments

Add a comment