Editing jQuery.fn.each vs. jQuery.fn.quickEach vs Ext.each This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) [The `quickEach` method](http://gist.github.com/500145) will pass a non-unique `jQuery` instance to the callback meaning that there will be no need to instantiate a fresh `jQuery` instance on each iteration. Most of the slow-down inherent in jQuery’s native iterator method (`each`) is the constant need to have access to jQuery’s methods, and so most developers see constructing multiple instances as no issue… A better approach would be `quickEach`. This Revision also compares against the Ext-Core library. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/ext-core/3.1.0/ext-core.js"></script> <script> var a = $('<div/>').append(Array(100).join('<a></a>')).find('a'); // we need a real JavaScript array for the Ext-Core test var b = a.toArray(); jQuery.fn.quickEach = (function() { var jq = jQuery([1]); return function(c) { var i = -1, el, len = this.length; try { while (++i < len && (el = jq[0] = this[i]) && c.call(jq, i, el) !== false); } catch (e) { delete jq[0]; throw e; } delete jq[0]; return this; }; }()); </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code a.each(function() { $(this).addClass('test'); }); Test 2 Title Async (check if this is an asynchronous test) Code a.quickEach(function() { this.addClass('test'); // jQuery object }); Test 3 Title Async (check if this is an asynchronous test) Code Ext.each(b, function(item) { Ext.fly(item).addClass('test'); // Ext.Element }); Test 4 Title Async (check if this is an asynchronous test) Code a.addClass('nano'); Test 5 Title Async (check if this is an asynchronous test) Code Ext.select(b).addClass('nano');