parent vs parents.eq

Benchmark created on


Description

Check if traversing through parents one at a time is faster than using parents() to pull the list of parents() then select a specific one with .eq(x)

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div id='div1'>
    <div id='div2'>
          <div id='div3'>
               <div id='div4'>
                    <div id='div5'>
                         <div id='div6'>
                             <div id='div7'></div>
                          </div>
                    </div>
               </div>
          </div>
     </div>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
parent()
$('#div7').parent().parent().parent().parent().parent().parent()
ready
parents()
$('#div7').parents().eq(6)
ready

Revisions

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