Selectors perf 3 (v11)

Revision 11 of this benchmark created on


Preparation HTML

<div id="childDiv">
        <input type="text" id="txtID" class="txtClass">
          Why Right to Left Thinking is Good
        </input>
        <p class="child">
          Blah Blah Blah
        </p>
      </div>
     
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script >
var $div = $('#childDiv'); 
var $div1 = $("div[id*='childDiv']");
var $div2 = $("[id='childDiv']");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
class selector
var xx = $('.txtClass');
ready
ID desend
var xxx = $('#childDiv .txtClass');
ready
ID desend 2
var xxx = $('#childDiv > .txtClass');
ready
element prefix
var xxx = $('input.txtClass');
ready
Find
var xxx = $('#childDiv').find('.txtClass');
ready
With context
var xxx = $('.txtClass',$('#childDiv'));
ready
2 Steps
var $obj = $('#childDiv');
xxx = $($obj).find('.txtClass');
ready
Direct
var obj = document.getElementById("childDiv");
xxx = obj.getElementsByClassName("txtClass");
ready
qq
var $div1 = $("div[id*='childDiv']");
 
ready
qq
var $div2 = $("[id='childDiv']");
ready
eee
var $div3 = $("#childDiv");
ready

Revisions

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