getElementById vs. querySelector

JavaScript performance comparison

Revision 300 of this test case created by Sunny Mui

Preparation code

<div>
<header>
<h1>Ultimate title</h1>
<nav>
<button>Click</button>
</nav>
</header>
<aside>Some stuff and other</aside>
<main>
   <section><h1>Title</h1></section>
   <section><h1>Other title</h1></section>
<div>
   <p id="bar" class="bar">Bar</p>
   <p id="baz">Baz</p>
   <p id="foo">Foo</p>
</div>
</main>
<footer>
<a href="#">Link</a>
</footer>
</div>
    

Preparation code output

<div> <header> <h1>Ultimate title</h1> <nav> <button>Click</button> </nav> </header> <aside>Some stuff and other</aside> <main> <section><h1>Title</h1></section> <section><h1>Other title</h1></section> <div> <p id="bar" class="bar">Bar</p> <p id="baz">Baz</p> <p id="foo">Foo</p> </div> </main> <footer> <a href="#">Link</a> </footer> </div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
querySelectorTopLevelParent
var top = document.querySelector("div");
pending…
querySelectorTag
var bar = document.querySelector("p");
pending…
querySelectorClass
var bar = document.querySelector(".bar");
pending…

Revisions

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

0 Comments

Ultimate title

Title

Other title

Bar

Baz

Foo