getElementById vs. querySelector

JavaScript performance comparison

Revision 289 of this test case created by

Preparation code

<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
   <employees>
	<actors>
		<actor id="1">Christian Bale</actor>
		<actor id="2">Liam Neeson</actor>
		<actor id="3">Michael Caine</actor>
	</actors>
	<foo:singers>
		<foo:singer id="4">Tom Waits</foo:singer>
		<foo:singer id="5">B.B. King</foo:singer>
		<foo:singer id="6">Ray Charles</foo:singer>
	</foo:singers>
   </employees>
   <tools>
	<knives>
		<Knive id="1">
			<color>red</color>
			<color>blue</color>
		</Knive >
	</knives>
   </tools>
</root>
    

Preparation code output

<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org"> <employees> <actors> <actor id="1">Christian Bale</actor> <actor id="2">Liam Neeson</actor> <actor id="3">Michael Caine</actor> </actors> <foo:singers> <foo:singer id="4">Tom Waits</foo:singer> <foo:singer id="5">B.B. King</foo:singer> <foo:singer id="6">Ray Charles</foo:singer> </foo:singers> </employees> <tools> <knives> <Knive id="1"> <color>red</color> <color>blue</color> </Knive > </knives> </tools> </root>

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
XPath
var bar = document.evaluate("//root//employees//foo:singers//foo:singer[@id='5']", document, null, 9, null).singleNodeValue;
pending…
getElementById
var bar = document.getElementById("5");
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

Christian Bale Liam Neeson Michael Caine Tom Waits B.B. King Ray Charles red blue