jQuery each2 plugin vs jQuery core .each method
JavaScript performance comparison
Info
Basically, if you're going to do $(this) inside an .each loop, you should consider using the jQuery each2 plugin instead, because it's specifically optimized for this extremely common use case!
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<!-- the plugin -->
<script src="http://github.com/cowboy/jquery-misc/raw/master/jquery.ba-each2.js"></script>
<script>
// Create a whole bunch of elements for iteration.
var elems = $('<div/>').append(Array(1000).join('<span/>')).children();
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
jQuery each2 plugin |
|
pending… |
jQuery core .each method |
|
pending… |
jQuery core .each, $(this) x 2 |
|
pending… |
jQuery core .each, $(this) x 4 |
|
pending… |
jQuery core .each, $(this) x 10 |
|
pending… |
Putting things into perspective... |
|
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 "Cowboy" Ben Alman
- Revision 2: published by "Cowboy" Ben Alman
- Revision 3: published
- Revision 4: published by David
- Revision 5: published by David
- Revision 6: published by Kyle Simpson and last updated
- Revision 7: published by Flatlineato
- Revision 13: published by Scott Rycroft
- Revision 15: published by Scott Rycroft
- Revision 16: published by Jason DiMeo
- Revision 18: published by Jason DiMeo
- Revision 22: published by creage
- Revision 23: published
- Revision 24: published
- Revision 25: published
1 comment
Simply: Wow! Gonna give it a try!