querySelector vs. getElementsByTagName (v66)

Revision 66 of this benchmark created on


Description

Compare the speed of querySelector("#...") getElementsByTagName(*) with a filter function (for sub selects)

Preparation HTML

<div id="container">
  <p id="foo">Foo</p>
  <p id="bar">Bar</p>
  <p id="baz">Baz</p>
</div>

Setup

var root = document.getElementById("container");

Test runner

Ready to run.

Testing in
TestOps/sec
getElementsByTagName
var bar = [].filter.call(root.getElementsByTagName("*"), function(e) { return e.id === "bar" })[0]
ready
querySelector
var bar = root.querySelector("#bar");
ready

Revisions

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