getElementById vs. querySelector

JavaScript performance comparison

Revision 133 of this test case created by test077

Preparation code

<table><tbody><tr><td id="123"></td></tr></tbody></table>
      
<script>
Benchmark.prototype.setup = function() {
  var element = document.createElement('div')
  element.innerHTML = '<label id="324"><input id="target" type="hidden"><span id="7788"></span></label>';
  document.getElementById('123').appendChild(element);

};
</script>

Preparation code output

<table><tbody><tr><td id="123"></td></tr></tbody></table>

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
getElementById
var input = document.getElementById("target");
pending…
element querySelector
var input = element.querySelector("#target");
pending…
document querySelector
var input = document.querySelector("#target");
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