querySelectorAll vs getElementsByTagName
JavaScript performance comparison
Info
Checking how querySelectorAll('parent child') or '.parent .child' selection performs against combinations of getElementsByTagName, getElementsByClassName and jQuery
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<ul class="root-ul"><li><a class="link word" href="#word">word</a>
</li><li><a class="link glass" href="#glass">glass</a>
</li><li><a class="link lorum" href="#lorum">lorum</a>
</li><li><a class="link ipsum" href="#ipsum">ipsum</a>
</li><li><a class="link dolor" href="#dolor">dolor</a>
</li><li><a class="link sit-amet" href="#sit-amet">sit-amet</a>
</li></ul>
<script>
Benchmark.prototype.teardown = function() {
window.console && console.log && console.log('nodes:',nodes.length, nodes);
};
</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 + getElementsByTagName |
|
pending… |
getElementsByTagName + getElementsByClassName |
|
pending… |
getElementsByClassName + getElementsByClassName |
|
pending… |
getElementsByClassName + getElementsByTagName |
|
pending… |
jQuery by CSS class |
|
pending… |
jQuery by Tag + class |
|
pending… |
jQuery by class + Tag |
|
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