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

Revision 16 of this benchmark created by Uuuuh on


Preparation HTML

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

Test runner

Ready to run.

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

Revisions

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