Selector context

JavaScript performance comparison

Revision 6 of this test case created by NPerfTestXXX

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    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));
   
    });
};

Benchmark.prototype.teardown = function() {
    $('#tree').empty();
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
$(".holder")
$(".holder").selector;
pending…
$(".holder", "#context")
$(".holder", "#context").selector;
pending…
$(".holder", $("#context"))
$(".holder", $("#context")).selector;
pending…
$(".holder", $context)
$(".holder", $context).selector;
pending…
$context.find(".holder")
$context.find(".holder").selector;
pending…
$context.filter('.holder')
$context.filter('.holder').selector;
pending…
$context.find('*').filter('.holder')
$context.find('*').filter('.holder').selector;
pending…
$("#context .holder")
$("#context .holder").selector;
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