getElementsByTagname vs. querySelector - on checked input elements (v15)

Revision 15 of this benchmark created by Dan on


Description

Tests how quickly you can retrieve a single input checked element on the page using getElementsByTagName vs querySelector.

Preparation HTML

<div id="inputcontainer">
<input id="a" type="radio"/>
<input id="b" type="radio"/>
<input id="c" type="radio"/>
<input id="d" type="radio"/>
<input id="e" type="radio" checked="checked"/>
<input id="f" type="radio"/>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
Using getElementsByTagName()
var tags = document.getElementsByTagName("input");
for(var i = 0; i < tags.length; i++)
{
    if(tags[i].checked)
    {
        var a = tags[i];
        break;
    }
}
ready
Using querySelector()
var a = document.querySelector("input:checked");

 
ready

Revisions

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