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

Revision 11 of this benchmark created by vamp 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 accumulator = [].slice.call(document.getElementsByTagName("a"));
ready
Using querySelector()
var accumulator  = document.querySelectorAll('a');
ready
qSA double copy
var accumulator = [].slice.call(document.querySelectorAll('a'));
ready

Revisions

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