querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName (v15)

Revision 15 of this benchmark created by Uuuuh on


Preparation HTML

<p id="foo" class="foo">
  <span class="bar">,,,</span>
</p>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelector
document.querySelector("#foo .bar");
ready
querySelectorAll
document.querySelectorAll("#foo .bar")[0];
ready
getElementById
document.getElementById("foo").getElementsByClassName('bar')[0];
ready
getElementsByClassName
document.getElementsByClassName("foo")[0].getElementsByClassName('bar')[0];
ready
getElementsByTagName
document.getElementsByTagName("p").getElementsByClassName('bar')[0];
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.