jquery_cached

JavaScript performance comparison

Revision 5 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 = {},
                DOMCache1 = {
                get: function ( selector, force )
                        {
                                if ( Store[selector] && !force )
                                {
                                        return Store[selector];
                                }
                               
                                return (Store[selector] = $(selector));
                        }
        },
        DOMCache2 = {
                storage : {},
                get: function (selector, force) {
                        if (this.storage[selector] && !force) {
                                return this.storage[selector];
                        }
                        return (this.storage[selector] = $(selector));
                }
        };

        win.DOMCache1 = DOMCache1;
win.DOMCache2 = DOMCache2;
}(window));
</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…
DOMCache1
DOMCache1.get('h1').addClass('inactive');
DOMCache1.get('h1').text('hello');
pending…
DOMCache1 chaining
DOMCache1.get('h1').addClass('inactive').text('hello');
pending…
DOMCache2
DOMCache2.get('h1').addClass('inactive');
DOMCache2.get('h1').text('hello');
pending…
DOMCache2 chaining
DOMCache2.get('h1').addClass('inactive').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