getElementsByTagname vs. querySelector - on checked input elements

JavaScript performance comparison

Revision 15 of this test case created by Dan

Preparation code

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

Preparation code output

<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

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
Using getElementsByTagName()
var tags = document.getElementsByTagName("input");
for(var i = 0; i < tags.length; i++)
{
    if(tags[i].checked)
    {
        var a = tags[i];
        break;
    }
}
pending…
Using querySelector()
var a = document.querySelector("input:checked");

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