getElementById vs. querySelector

JavaScript performance comparison

Revision 71 of this test case created by

Preparation code

<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div><div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div id="find-me">
<div class="find-me"/>
<div class="find-me"/>
<div class="find-me"/>
</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
<div>Padding for a more fair reflection of selection work being done</div>
    

Preparation code output

<div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div><div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div id="find-me"> <div class="find-me"/> <div class="find-me"/> <div class="find-me"/> </div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</div> <div>Padding for a more fair reflection of selection work being done</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")[1];
pending…
querySelector(id)
var found = document.querySelector("#find-me");
pending…
querySelector(class)
var found = document.querySelector(".find-me")[1];
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…
querySelector(#id .class)
var found = document.querySelector("#find-me .find-me")[1];
pending…
getElementById(id).getElementsByClassName(class)
var found = document.getElementById("find-me").getElementsByClassName("find-me")[1];
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

Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done
Padding for a more fair reflection of selection work being done