querySelectorAll vs getElementsByTagName (v110)

Revision 110 of this benchmark created on


Description

Accessed all elements of the array, since getElementsByTagName is a "live list" and doesn't actually calculate anything.

The previous tests are all skewed by this (although gEBTN is still a lot faster).

Preparation HTML

<div>
  <ul>
    <li><a href="#">item 1</a></li>
    <li><a href="#">item 2</a></li>
    <li><a href="#">item 3</a></li>
  </ul>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelectorAll
var nodes = document.querySelectorAll('a')
var length = nodes.length
var node1 = nodes[0]
var node2 = nodes[1]
var node3 = nodes[2]
ready
getElementsByTagName
var nodes = document.getElementsByTagName('a')
var length = nodes.length
var node1 = nodes[0]
var node2 = nodes[1]
var node3 = nodes[2]
ready

Revisions

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