querySelector vs. getElementsByTagName

JavaScript performance comparison

Revision 318 of this test case created by Pieter Van Parys

Preparation code

<div id="container">
  <p id="foo">Foo</p>
  <p id="bar">Bar</p>
  <p id="baz">Baz</p>
</div>
      
<script>
Benchmark.prototype.setup = function() {
  root = document.getElementById("container");

};
</script>

Preparation code output

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

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
querySelector
var bar = root.querySelector("p");
pending…
getElementsByTagName
var bar = root.getElementsByTagName("p")[0]
pending…

Compare results of other browsers

Revisions

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

0 Comments

Foo

Bar

Baz