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
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
| Test | Ops/sec | |
|---|---|---|
| jQuery each2 plugin | |
pending… |
jQuery core .each method |
|
pending… |
Results
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
0 comments