querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName vs getElementsByName (v35)

Revision 35 of this benchmark created by hooriza on


Preparation HTML

<section>
  <p id="foo" class="foo" name="fooname"></p>
  <span class="bar" name="barname">,,,</span>
</section>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelector by ID
document.querySelector("#foo");
ready
querySelectorAll by ID
document.querySelectorAll("#foo")[0];
ready
getElementById
document.getElementById("foo");
ready
getElementsByClassName
document.getElementsByClassName("foo")[0];
ready
getElementsByTagName
document.getElementsByTagName("p")[0];
ready
getElementsByName
document.getElementsByName("fooname")[0];
ready
querySelector by ClassName
document.querySelector(".foo");
ready
querySelectorAll by ClassName
document.querySelectorAll(".foo")[0];
ready
querySelector by TagName
document.querySelector("p");
ready
querySelectorAll by TagName
document.querySelectorAll("p")[0];
ready
querySelector by Name
document.querySelector("[name=fooname]");
ready
querySelectorAll by Name
document.querySelectorAll("[name=fooname]")[0];
ready

Revisions

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