querySelectorAll vs getElementsByTagName (v91)

Revision 91 of this benchmark created on


Preparation HTML

<script>
function $$c(x, y){
  var result = [];
  var count = 0;
  for(var i=0; i < x.length; i++){
    if(x[i].className == y){
      results[count++] = x[i];
    }
  }
  return(result);
}

function $unsetClass(x, y){
  for(var i=0; i < x.length; i++){
    x[i].className.replace(y,'');
  }
}
</script>
<div>
  <ul>
    <li><a href="#">item 1</a></li>
    <li><a href="#">item 2</a></li>
    <li><a class="xxx" href="#">item 3</a></li>
  </ul>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelectorAll
var nodes = document.querySelectorAll('a.xxx')
ready
getElementsByTagName
var nodes = document.getElementsByTagName('a');
$$c(nodes,"xxx");
ready
var nod = document.getElementsByTagName('a');
$unsetClass(nod,"xxx");
ready

Revisions

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