getElementById vs. querySelector (v93)

Revision 93 of this benchmark created on


Description

Compare the speed of getElementById to querySelector

Preparation HTML

<p id="foo">Foo</p>
<p id="bar">Bar</p>
<p id="baz">Baz</p>

Setup

var cbar = document.getElementById("bar");

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
var bar = document.getElementById("bar");
bar.innerHTML = "foo";
ready
querySelector
var bar = document.querySelector("#bar");
bar.innerHTML = "foo";
ready
cache
cbar.innerHTML = "foo";
ready

Revisions

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