querySelector vs getElementsByTagName (v119)

Revision 119 of this benchmark created on


Preparation HTML

<div>
  <ul id="list" class="foo">
    <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
querySelector
var nodes = document.querySelector('a')
ready
getElementsByTagName
var nodes = document.getElementsByTagName('a')[0]
ready
getElementsByClassName
var nodes = document.getElementsByClassName('foo')[0]
ready
getElementById
var nodes = document.getElementById('list')
ready
querySelector class name
var nodes = document.querySelector('.foo')
ready
querySelector ID
var nodes = document.querySelector('#list')
ready

Revisions

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