Find vs Filter vs Traverse

Benchmark created by Vuly on


Preparation HTML

<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>

Test runner

Ready to run.

Testing in
TestOps/sec
Find
$('#top li:visible').each(function(z) {
  value = $(this).find('span[name=test]').html();
});
ready
Filter
$('#top li:visible').each(function(z) {
  value = $(this).filter('span[name=test]').html();
});
ready
Traverse one children
$('#top li:visible').each(function(z) {
  value = $(this).children('div > span[name=test]').html();
});
ready
Traverse 2 children
$('#top li:visible').each(function(z) {
  value = $(this).children('div').children('span[name=test]').html();
});
ready
Traverse children, no name search
$('#top li:visible').each(function(z) {
  value = $(this).children('div > span').html();
});
ready
Traverse 2 children, no name search
$('#top li:visible').each(function(z) {
  value = $(this).children('div').children('span').html();
});
ready

Revisions

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