getElementById vs. querySelector

JavaScript performance comparison

Revision 70 of this test case created by

Preparation code

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

Preparation code output

<div id="find-me" class="find-me">Find me!</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
getElementById
var found = document.getElementById("find-me");
pending…
getElementsByClassName
var found = document.getElementsByClassName(".find-me")[0];
pending…
querySelector(id)
var found = document.querySelector("#find-me");
pending…
querySelector(class)
var found = document.querySelector(".find-me");
pending…
querySelector(tag#id)
var found = document.querySelector("div#find-me");
pending…
querySelector(tag.class)
var found = document.querySelector("div.find-me");
pending…
getElementsByTagName
var found = document.getElementsByTagName("div")[0];
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

Find me!