selector test id/id id/id class

JavaScript performance comparison

Revision 25 of this test case created by Dmitry Erman

Info

Rev 25 Notes: Fixed test 5 - context was backwards. Added test 7/8 to demonstrate performance of using getElementByID to grab the initial context. Also, this is not a real apples to apples test. Comparing just the main ID selector to filtering or more complex selectors are not equivalent performance metrics. Note the major difference between letting jQuery find the ID and letting the browser do it.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>


<div id="Mytbl">
<div id="MyElement"></div>
<div class="MyClass"></div>
</div>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Direct ID
$('#MyElement');


 
pending…
Nested ID's
$('#Mytbl #MyElement')
pending…
ID - Class
$('#Mytbl .MyClass')
pending…
find()
$("#Mytbl").find(".MyClass");
pending…
Context
$("div.MyClass", "#Mytbl");
pending…
ID / Class with Tag
$('#Mytbl div.MyClass')
pending…
Direct ID getElementByID w/ jQuery
$(document.getElementById("Mytbl"));
 
pending…
getElementByID as context
$("div.MyClass", document.getElementById("Mytbl"));
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. Here’s a list of current revisions for this page:

0 comments

Add a comment