getElementsByTagname("a")[0] vs. querySelector("a") (v17)

Revision 17 of this benchmark created on


Description

Tests how quickly you can iterate through multiple elements on the page using getElementsByTagName("a") vs. querySelector("a").

Preparation HTML

<script src="//code.jquery.com/jquery-git2.min.js"></script>

<input type="password"></input><input type="password"></input>
<input type="password"></input><input type="password"></input>

Setup

var list, result, i, len;
    var hasFields = false;

Teardown


    hasFields = false;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Using getElementsByTagName()
var fields = document.getElementsByTagName("input");

if (fields && fields.length > 0) {
  hasFields = true;
}
ready
Using querySelectorAll()
var fields = document.querySelectorAll("input[type='password']");

if (fields && fields.length > 0) {
  hasFields = true;
}
ready
Using querySelector()
var fields = document.querySelector("input[type='password']");

if (fields && fields.length > 0) {
  hasFields = true;
}
ready
jQuery
fields = jQuery("input[type=password]");

if (fields && fields.length > 0) {
  hasFields = true;
}
ready

Revisions

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