query selecgtor vs get element by id (v2)

Revision 2 of this benchmark created on


Preparation HTML

<div></div>
<div></div>
<div></div>
<div></div>
<div id="holder">
<div class="x" id="x"></div>
</div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>

Setup

function getId() {
     return "x";
    }
    
    var doc = document.getElementById("holder");

Test runner

Ready to run.

Testing in
TestOps/sec
getelementbyid
document.getElementById("x")
ready
get element by id and function call
document.getElementById(getId())
ready
get element by class name
document.getElementsByClassName("x")
ready
query selector
doc.querySelector(".x")
ready

Revisions

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