JQuery :first vs .first() vs. eq (v4)

Revision 4 of this benchmark created on


Preparation HTML

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

<div>AAAA</div>
<div>BBBB</div>
<div>CCCC</div>
<div>DDDD</div>
<div>EEEE</div>

<div><span>aaaa</span></div>
<div><span>bbbb</span></div>
<div><span>cccc</span></div>
<div><span>dddd</span></div>
<div><span>eeee</span></div>

Test runner

Ready to run.

Testing in
TestOps/sec
.first
$("div").first();
ready
:first
$("div:first");
ready
get(0)
$("div").get(0);
ready
[0]
$("div")[0];
ready
.eq
$("div").eq(0);
ready
.filter(:first)
$("div").filter(":first");
ready
slice
$("div").slice(0,1);
ready

Revisions

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