Find vs Filter vs Traverse

JavaScript performance comparison

Test case created by Vuly

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ul id="top">
  <li>
    <div>
      bbb
      <span name="test">
        a
      </span>
    </div>
  </li>
  <li>
    <div>
      bbb
      <span name="test">
        a
      </span>
    </div>
  </li>
  <li style="display:none;">
    <div>
      bbb
      <span name="test">
        a
      </span>
    </div>
  </li>
</ul>
<script>
  var value;
</script>

Preparation code output

  • bbb a
  • bbb a
  • bbb a

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Find
$('#top li:visible').each(function(z) {
  value = $(this).find('span[name=test]').html();
});
pending…
Filter
$('#top li:visible').each(function(z) {
  value = $(this).filter('span[name=test]').html();
});
pending…
Traverse one children
$('#top li:visible').each(function(z) {
  value = $(this).children('div > span[name=test]').html();
});
pending…
Traverse 2 children
$('#top li:visible').each(function(z) {
  value = $(this).children('div').children('span[name=test]').html();
});
pending…
Traverse children, no name search
$('#top li:visible').each(function(z) {
  value = $(this).children('div > span').html();
});
pending…
Traverse 2 children, no name search
$('#top li:visible').each(function(z) {
  value = $(this).children('div').children('span').html();
});
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