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

Revision 41 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<p id="foo" class="foo">
  bar
</p>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelector
document.querySelector("#foo");
ready
querySelectorAll
document.querySelectorAll("#foo")[0];
ready
getElementById
document.getElementById("foo");
ready
getElementsByClassName
document.getElementsByClassName("foo")[0];
ready
getElementsByTagName
document.getElementsByTagName("p");
ready
querySelector by class
document.querySelector(".foo");
ready
jQuery by id
$("#foo");
ready
jQuery by class name
$(".foo");
ready
jQuery by tag name
$("p");
ready

Revisions

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