querySelector vs getElement(s)ByWhatever vs .firstChild

Benchmark created on


Preparation HTML

<p id="id" class="class">some text 0</p>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelector
const element = document.querySelector(".class");
ready
getElementsByClassName
const element = document.getElementsByClassName("class");
ready
getElementsByTagName
const element = document.getElementsByTagName("p");
ready
getElementById
const element = document.getElementById("id");
ready

Revisions

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