getElementById vs. querySelector (v249)

Revision 249 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<p id="pp-0">Foo</p>
<p id="pp-1">Bar</p>
<p id="pp-2">Baz</p>
<p class="component-pp-0">Foo</p>
<p class="component-pp-1">Bar</p>
<p class="component-pp-2">Baz</p>

Setup

var id = "pp-1";

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
var bar = $(document.getElementById(id));
ready
querySelector
var bar = $(".component-" + id);
ready

Revisions

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