jQuery.fn.each vs. quickEach vs. each2
JavaScript performance comparison
Info
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
var a = $('<div/>').append(Array(100).join('<a></a>')).find('a');
// My each2 plugin
(function($) {
var jq = $([]);
$.fn.each2 = function(fn) {
var i = -1;
while ((jq[0] = this[++i]) && fn.call(jq[0], i, jq) !== false) {}
return this;
};
})(jQuery);
(function($) {
var jq = $([]);
$.fn.each2_ref = function(fn) {
var i = -1,
elem;
while ((elem = jq[0] = this[++i]) && fn.call(elem, i, jq) !== false) {}
return this;
};
})(jQuery);
(function($) {
var jq = $([]);
$.fn.each2_len = function(fn) {
var i = -1,
len = this.length;
while (++i < len && (jq[0] = this[i]) && fn.call(jq[0], i, jq) !== false) {}
delete jq[0];
return this;
};
})(jQuery);
(function($) {
var jq = $([]);
$.fn.each2_ref_len = function(fn) {
var i = -1,
len = this.length,
elem;
while (++i < len && (elem = jq[0] = this[i]) && fn.call(elem, i, jq) !== false) {}
delete jq[0];
return this;
};
})(jQuery);
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
no elem re length comparison |
|
pending… |
original jQuery.fn.each (reference) |
|
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 James Padolsey
- Revision 2: published by "Cowboy" Ben Alman
- Revision 3: published by "Cowboy" Ben Alman
- Revision 9: published by NilColor
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 18: published
- Revision 19: published
- Revision 22: published by mhitza
- Revision 27: published
- Revision 28: published by Test
- Revision 29: published
- Revision 30: published by Erwan Legrand
- Revision 31: published
- Revision 32: published
- Revision 33: published
- Revision 34: published by Vaibhav
- Revision 35: published
- Revision 36: published
- Revision 37: published
- Revision 38: published
- Revision 39: published
- Revision 41: published by Jason
- Revision 42: published by Dim
- Revision 47: published by Andy Harman
- Revision 48: published by Andy Harman and last updated
- Revision 50: published by private_face
- Revision 54: published
- Revision 56: published by David Seigle
- Revision 58: published by Andy Harman
- Revision 59: published by David Seigle
- Revision 63: published by Andy Harman
- Revision 64: published by roviury
- Revision 66: published by Andy Harman
- Revision 69: published by Andy Harman and last updated
- Revision 70: published
- Revision 71: published
- Revision 73: published
- Revision 74: published
- Revision 76: published
- Revision 77: published
- Revision 78: published by Jeffrey
- Revision 79: published
- Revision 80: published
- Revision 81: published by nod_ and last updated
- Revision 82: published by Andy Harman
- Revision 83: published by Kirill
- Revision 85: published
0 comments