getElementById vs. querySelector

JavaScript performance comparison

Revision 6 of this test case created by

Preparation code

<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>

    

Preparation code output

<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

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
getElementById
var bar = document.getElementById("bar");
pending…
querySelector
var bar = document.querySelector("#bar");
pending…

Compare results of other browsers

Revisions

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

0 Comments

Foo

Foo

Foo

Foo

Foo

Foo

Foo

Foo

Foo

Foo

Foo

Foo

Foo

Foo

Bar

Foo

Bar

Foo

Bar

Foo

Bar

Foo

Bar

Foo

Bar

Baz

Foo

Foo

Foo

Foo

Bar

Baz

Foo

Bar

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz

Foo

Bar

Baz