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

Revision 21 of this benchmark created 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("p .bar");
ready
elementselector
var test = document.getElementsByTagName('p');

test[0].getElementsByClassName('bar');
ready
querySelector Id
document.querySelector("#foo .bar");
ready

Revisions

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