jQuery Parents vs Closest (v56)

Revision 56 of this benchmark created by Enoc Bahena on


Description

Similar to parent vs closest, only this time testing when searching >1 level of the DOM ancestors.

Preparation HTML

<div>
  <table>
    <tr>
      <td>
        <ul>
          <li>
            1
          </li>
          <li>
            2
          </li>
          <li>
            3
          </li>
          <li>
            4
          </li>
          <li>
            5
          </li>
          <li>
            6
            <ul>
              <li>
                1
              </li>
              <li>
                2
              </li>
              <li>
                2
              </li>
              <li>
                3
                <ul id="end" class="end">
                  <li>
                    1
                  </li>
                  <li>
                    2
                  </li>
                  <li>
                    3
                  </li>
                  <li>
                    <a id="start" class="start">4</a>
                  </li>
                  <li>
                    5
                  </li>
                </ul>
              </li>
              <li>
                4
              </li>
              <li>
                5
              </li>
            </ul>
          </li>
          <li>
            7
          </li>
          <li>
            8
          </li>
          <li>
            9
          </li>
          <li>
            10
          </li>
        </ul>
      </td>
    </tr>
  </table>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Parents
$(".start").parents("ul.end").first();
ready
Closest
$(".start").closest("ul.end");
ready
Parents by ID
$("#start").parent("li").parent("ul.end")
ready
Closest by ID
$("#start").closest("li").closest("ul.end");
ready
ID Parent:first
$("#start").parents("ul.end");
ready

Revisions

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