.find() Versus Selectors

JavaScript performance comparison

Revision 4 of this test case created

Info

Will the battle never end?

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="null">
</div>
<div id="a">
  <div class="null">
  </div>
  <div class="null">
  </div>
  <div class="null">
  </div>
  <div class="a">
    <div class="c">
      <div class="null">
      </div>
      <div class="b">
      </div>
      <div class="null">
      </div>
    </div>
    <div class="null">
    </div>
  </div>
</div>
<script>
Benchmark.prototype.setup = function() {
    var $a = $('#a');
};
</script>

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
Selector
$('#a .b');
pending…
Context
$('.b', $('#a'));
pending…
.find()
$('#a').find('.b')
pending…
Cached .find()
$a.find('.b')
pending…
Cached Context
$('.b', $a)
pending…
Speed .find()
$.find('.b');
pending…
Speed .find() with context
$.find('.b', $a);
pending…
$.find version of "selector"
$.find('#a .b');
pending…
Just '.b'
$('.b');
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