getElementById vs. querySelector (v42)

Revision 42 of this benchmark created on


Description

Compare the speed of getElementById to querySelector

Preparation HTML

<p class="foo">Foo</p>
<p class="bar">Bar</p>
<p class="foo">Baz</p>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementByClassName
var bar = document.getElementsByClassName('foo')
ready
querySelector
var bar = document.querySelector(".foo");
ready

Revisions

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