jquery parent_children vs find

JavaScript performance comparison

Test case created by IllusionMH

Preparation code

<ul>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
  <li>
    <a href="#"><img src="#" /></a>
  </li>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
  <li>
    <a href="#"><img src="#"/></a>
  </li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    $(".active").removeClass("active");
    var elem1 = $("li a").eq(4)[0],
        elem2 = $("li").eq(4)[0];
};
</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
parent_children
$(elem1).addClass('active').parent().addClass('active').end().children().addClass('active')
pending…
find
$(elem2).find('a,img').add(elem2).addClass('active');
pending…
parent_children long
$(elem1).parent().addClass('active');
$(elem1).children().addClass('active');
$(elem1).addClass('active');
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