jquery_cached

JavaScript performance comparison

Revision 3 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));
$(document).ready(function() {
  window.$h1 = $('h1');
  window.$h2 = $('h2');
});
</script>
<h1>Header 1</h1>
<h2>Header 2</h2>

Preparation code output

Header 1

Header 2

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');
$('h2').addClass('inactive');
$('h2').text('hello');
 
pending…
jQuery Cached
var $h1 = $('h1'), $h2 = $('h2');

$h1.addClass('inactive');
$h1.text('hello');
$h2.addClass('inactive');
$h2.text('hello');
pending…
jQuery Chaining
$('h1').addClass('inactive').text('hello');
$('h2').addClass('inactive').text('hello');
pending…
DOMCache
DOMCache.get('h1').addClass('inactive');
DOMCache.get('h1').text('hello');
DOMCache.get('h2').addClass('inactive');
DOMCache.get('h2').text('hello');
 
pending…
DOMCache chaining
DOMCache.get('h1').addClass('inactive').text('hello');
DOMCache.get('h2').addClass('inactive').text('hello');
pending…
Manual Cache
window.$h1.addClass('inactive')
window.$h1.text('hello');
window.$h2.addClass('inactive')
window.$h2.text('hello');
pending…
Manual Cache Chaining
window.$h1.addClass('inactive').text('hello');
window.$h2.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