querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName vs $ (v39)

Revision 39 of this benchmark created by Owain Llewellyn 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
jQuery - Element
$('p')
ready
jQuery - Class
$('p.foo')
ready
jQuery - Id
$('#foo')
ready
jQuery
$('.foo')
ready

Revisions

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