.first() vs :first vs eq(0) (v17)

Revision 17 of this benchmark created on


Description

which is faster .first(), :first or .eq(0)?

Stack Overflow Question: http://stackoverflow.com/questions/2312761/jquery-first-vs-first

Slightly more complicated DOM.

Preparation HTML

<div><div>
<ul>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
  <li>Four</li>
  <li>Five</li>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
  <li>Four</li>
  <li>Five</li>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
  <li>Four</li>
  <li>Five</li>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
  <li>Four</li>
  <li>Five</li>
</ul>
</div></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
.first()
$('ul li').first().length == 0
 
ready
:first
$('ul li:first').length == 0
 
ready
.eq(0)
$('ul li').eq(0).length == 0
 
ready

Revisions

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