jquery_cached

Benchmark created by Tomas Corral 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));
</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

Revisions

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