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

Revision 9 of this benchmark created by Jorge Chamorro on


Description

Tests how quickly you can retrieve a non-live collection using getElementsByTagName("a")+copy vs. querySelector("a") vs .querySelector("a")+copy

Preparation HTML

<ul>
<li><a href="#">Item</a></li><li><a href="#">Item</a></li><li><a href="#">Item</a></li><li><a href="#">Item</a></li><li><a href="#">Item</a></li></ul>
<script>
  var accumulator;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Using getElementsByTagName()
var result = document.getElementsByTagName("a");
var i = result.length;
var r = [];
while (i--) r.push(result[i]);
accumulator = r;
ready
Using querySelector()
var r = document.querySelectorAll('a');
accumulator = r;
ready
qSA double copy
var result = document.querySelectorAll('a');
var i = result.length;
var r = [];
while (i--) r.push(result[i]);
accumulator = r;
ready

Revisions

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