NodeList vs. array 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>
function toArray(collection) {
var result = [],
i = -1;
while (result[++i] = collection[i]) {};
result.length--;
return result;
}
var liveList = document.getElementsByTagName('a');
var statList = document.querySelectorAll('a');
var liveArr = toArray(liveList);
var statArr = toArray(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 |
|
pending… |
Static List |
|
pending… |
Array of Live List |
|
pending… |
Array of Static List |
|
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:
- Revision 1: published by John-David Dalton
- Revision 3: published
- Revision 4: published
- Revision 5: published by Yaffle
- Revision 6: published by Mumtaz
- Revision 7: published by pll
- Revision 9: published
0 comments