getElementById vs. nested querySelector

JavaScript performance comparison

Revision 117 of this test case created by DarkPark

Preparation code

<div id="block1">
	<div id="block2">
		<div id="block3">
			<div id="block4">
				<div id="block5">
					<div id="block6">
						<div id="block7">
							<div id="block8">
								<div id="block9">
									<div id="block10">
										content
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
      
<script>
Benchmark.prototype.setup = function() {
  var block9 = document.getElementById('block9');

};
</script>

Preparation code output

<div id="block1"> <div id="block2"> <div id="block3"> <div id="block4"> <div id="block5"> <div id="block6"> <div id="block7"> <div id="block8"> <div id="block9"> <div id="block10"> content </div> </div> </div> </div> </div> </div> </div> </div> </div> </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
getElementById level 1
var block = document.getElementById('block1');
pending…
getElementById level 10
var block = document.getElementById('block10');
pending…
querySelector simple
var block = document.querySelector('#block10');
pending…
querySelector nested
var block = block9.querySelector('div');
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

content