jquery_cached (v4)

Revision 4 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
(function (win)
{
        var Store = {},
                DOMCache = {
                get: function ( selector, force )
                        {
                                if ( Store[selector] && !force )
                                {
                                        return Store[selector];
                                }
                                
                                return (Store[selector] = $(selector));
                        }
        };
        win.DOMCache = DOMCache;
}(window));
$C = (function($){
var DOMCache= {};
 
return function(selector, force) {
if (DOMCache[selector] && !force) {
return DOMCache[selector];
}

return (DOMCache[selector] = $(selector));
}
})(jQuery);
</script>
<h1>Header</h1>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery
$('h1').addClass('inactive');
$('h1').text('hello');
ready
jQuery Cached
var $h1 = $('h1');

$h1.addClass('inactive');
$h1.text('hello');
ready
jQuery Chaining
$('h1').addClass('inactive').text('hello');
ready
DOMCache
DOMCache.get('h1').addClass('inactive');
DOMCache.get('h1').text('hello');
ready
DOMCache chaining
DOMCache.get('h1').addClass('inactive').text('hello');
ready
DOMCache via $C
$C('h1').addClass('inactive');
$C('h1').text('hello');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.