querySelectorAll vs getElementById

JavaScript performance comparison

Revision 74 of this test case created by Andrey Kindin

Preparation code

<p id="foo">bar</p>
      
<script>
Benchmark.prototype.setup = function() {
  var § = function(query){
  	if (query[0] == "#"){
  		return document.getElementById(query.slice(1));
  	}else{
  		return document.querySelectorAll(query);
  	}
  };

};
</script>

Preparation code output

<p id="foo">bar</p>

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 result = document.getElementById('foo');
pending…
querySelectorAll
var result = document.querySelectorAll('#foo');
pending…
select
var result = §("#foo");
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

bar