Selector context

Benchmark created on


Preparation HTML

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

<div id="tree"></div>

Setup

function CreateNDepthTree(N) {
      if (N == 2) return $('<div/>', {
        id: 'context'
      }).append(CreateNDepthTree(N - 1));
      else if (N == 1) return $('<div></div>', {
        class: 'holder'
      }).html('<h3>Leaf</h3>');
      else return $('<div/>').append(CreateNDepthTree(N - 1));
    }
    var $context;
    
    $(document).ready(function() {
    
      $context = $("#context");
      $('#tree').append(CreateNDepthTree(1000));
    
    });

Teardown


    $('#tree').empty();
  

Test runner

Ready to run.

Testing in
TestOps/sec
$(".holder")
$(".holder").selector;
ready
$(".holder", "#context")
$(".holder", "#context").selector;
ready
$(".holder", $("#context"))
$(".holder", $("#context")).selector;
ready
$(".holder", $context)
$(".holder", $context).selector;
ready
$context.find(".holder")
$context.find(".holder").selector;
ready
$context.filter('.holder')
$context.filter('.holder').selector;
ready
$context.find('*').filter('.holder')
$context.find('*').filter('.holder').selector;
ready

Revisions

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