getElementById vs. querySelector (v68)

Revision 68 of this benchmark created on


Description

Compare the speed of the multitude of ways to select a node in JavaScript.

Preparation HTML

<div id="find-me" class="find-me">Find me!</div>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
var found = document.getElementById("find-me");
ready
getElementsByClassName
var found = document.getElementsByClassName(".find-me")[0];
ready
querySelector(id)
var found = document.querySelector("#find-me");
ready
querySelector(class)
var found = document.querySelector(".find-me");
ready

Revisions

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