jQuery Selector Perf - Select right to left (v7)

Revision 7 of this benchmark created by Kevin on


Description

The Sizzle engine acts much like the selector that the browser uses internally.

It parses from right to left.

For best performance this means that a selector will benefit when it's more specific is on the right side, or less specific on the left side.

And likewise it will be slower when it's less specific on the right side or more specific on the lef side.

Preparation HTML

<div>random</div>
<div id="wrapper">
 <div><label>Hi</label></div>
 <span id="labeler">Hi</span>
 <span id="inputer">Hi</span>
 </form>
</div>
<div>random</div>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Left to Right
jQuery('div#wrapper > span');
ready
Right to Left
jQuery('div > span#labeler');
ready
Tight
jQuery('div#wrapper > span#labeler');
ready
Loose
jQuery('div > span');
ready
Right to Left id only
jQuery('div > #labeler');
ready
id
jQuery('#labeler');
ready

Revisions

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