.first() vs :first vs eq(0)
JavaScript performance comparison
Info
which is faster .first(), :first or .eq(0)?
Stack Overflow Question: http://stackoverflow.com/questions/2312761/jquery-first-vs-first
Preparation code
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
Preparation code output
- One
- Two
- Three
- Four
- Five
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
.first() |
|
pending… |
:first |
|
pending… |
.eq(0) |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Simon
- Revision 2: published
- Revision 3: published by Dennis Kim
- Revision 4: published
- Revision 5: published by Faisal Sayed
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
0 comments