querySelectorAll vs getElementsByTagName
JavaScript performance comparison
Preparation code
<div id="test">
<ul>
<li>
<a href="#">1</a>
</li>
<li>
<a href="#">2</a>
</li>
<li>
<a href="#">3</a>
</li>
</ul>
</div>
<script>
var slice = Array.prototype.slice;
function toArray(a) {
return slice.call(a);
}
var div = document.getElementById('test');
function test(a) {
if (a.map(function(e) {
return e.innerHTML;
}).join('') !== '123') {
throw new Error('Wrong result!');
}
}
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
querySelectorAll |
|
pending… |
getElementsByTagName |
|
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 Andrew Hedges
- Revision 17: published
- Revision 20: published by Jeff Larson
- Revision 21: published by Sebastian Poreba
- Revision 22: published by MONTILLET
- Revision 25: published
- Revision 26: published
- Revision 27: published by Philip Tellis
- Revision 28: published by Carl Letourneau
- Revision 29: published
- Revision 30: published by Philip Tellis
- Revision 32: published
- Revision 33: published
- Revision 34: published
- Revision 35: published
- Revision 36: published
- Revision 37: published by Derp
- Revision 38: published
- Revision 39: published
- Revision 40: published by Zebulon84
- Revision 41: published by Jim Montgomery
- Revision 42: published by Jim Montgomery
- Revision 43: published
- Revision 44: published by Jim Montgomery
- Revision 45: published
- Revision 46: published
- Revision 47: published
- Revision 48: published by Adam
0 comments