getElementById vs. querySelector (v6)

Revision 6 of this benchmark created on


Description

Compare the speed of getElementById to querySelector

Preparation HTML

<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo</p>

<p id="foo">Foo</p>
</p>

<p>Foo</p>
<p>Bar</p>
<p>Foo</p>
<p>Bar</p>
<p>Foo</p>
<p>Bar</p>
<p>Foo</p>
<p>Bar</p>
<p>Foo</p>
<p>Bar</p>

<p>Foo</p>
<p>Bar</p>
<p>Baz</p>
<p>Foo</p>
<p>Foo</p>
<p>Foo

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

</p>


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

<p>Foo</p>
<p>Bar</p>
<p>Baz</p>
<p>Foo</p>
<p>Bar</p>
<p>Baz</p>
<p>Foo</p>
<p>Bar</p>
<p>Baz</p>
<p>Foo</p>
<p>Bar</p>
<p>Baz</p>
<p>Foo</p>
<p>Bar</p>
<p>Baz</p>

Test runner

Ready to run.

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

Revisions

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