jquery_cached

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

<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>

Preparation code output

Header

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery
$('h1').addClass('inactive');
$('h1').text('hello');
pending…
jQuery Cached
var $h1 = $('h1');

$h1.addClass('inactive');
$h1.text('hello');
pending…
jQuery Chaining
$('h1').addClass('inactive').text('hello');
pending…
DOMCache
DOMCache.get('h1').addClass('inactive');
DOMCache.get('h1').text('hello');
pending…
DOMCache chaining
DOMCache.get('h1').addClass('inactive').text('hello');
pending…
DOMCache via $C
$C('h1').addClass('inactive');
$C('h1').text('hello');
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:

0 comments

Add a comment