parent vs parents.eq (v2)

Revision 2 of this 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>
<style>
#div1 *{padding:5px;border:1px solid #999;background-color:#fff;}
</style>
<div id='div1'>1
    <div id='div2'>2
          <div id='div3'>3
               <div id='div4'>4
                    <div id='div5'>5
                         <div id='div6'>6
                             <div id='div7'>7</div>
                          </div>
                    </div>
               </div>
          </div>
     </div>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
parent()
$('#div7').parent().parent().parent().parent().parent().parent().css("border","1px solid blue")
ready
parents()
$('#div7').parents().eq(5).css("background-color","red")
ready
parents(eq())
$('#div7').parents(":eq(6)").css("background-color","green")
ready

Revisions

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