NodeList vs. array (slice) iteration
JavaScript performance comparison
Preparation code
<div>
<ul>
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
<li><a href="#">item 3</a></li>
</ul>
</div>
<script>
var liveList = function() {
return document.getElementsByTagName('a');
},
statList = function() {
return document.querySelectorAll('a');
},
liveArr = function() {
return Array.prototype.slice.apply(liveList());
},
statArr = function() {
return Array.prototype.slice.apply(statList());
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Live List (while) |
|
pending… |
Static List (while) |
|
pending… |
Array of Live List (while) |
|
pending… |
Array of Static List (while) |
|
pending… |
Live List (for) |
|
pending… |
Static List (for) |
|
pending… |
Array of Live List (for) |
|
pending… |
Array of Static List (for) |
|
pending… |
Live List (while) (--i) |
|
pending… |
Static List (while) (--i) |
|
pending… |
Array of Live List (while) (--i) |
|
pending… |
Array of Static List (while) (--i) |
|
pending… |
Live List (for) (++i) |
|
pending… |
Static List (for) (++i) |
|
pending… |
Array of Live List (for) (++i) |
|
pending… |
Array of Static List (for) (++i) |
|
pending… |
Refined Live (for)1 |
|
pending… |
Refined Live (for)2 |
|
pending… |
Refined Live (for)3 |
|
pending… |
Live (while!!)1 |
|
pending… |
Live (while!!)2 |
|
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