Flicker - Variable Cache

Benchmark created by Flicker on


Description

Check to see if caching the JQuery function is quicker.

Preparation HTML

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
No Cache
jQuery(document).ready(function() {
(function() {
    var flicker = 0;

    jQuery('#flicker').hover(
        function() {
           flicker = setInterval(function() {
               if (jQuery('#flicker img.active').next('img').length > 0) {
                   jQuery('#flicker img.active').removeClass('active').next('img').addClass('active');
                   } else {
                   jQuery('#flicker img').removeClass('active');
                   jQuery('#flicker img:first-child').addClass('active');
               } 
           }, 200);
         }, 
         function() {
           clearInterval(flicker);
         }
     ); 
})();
});
ready
With Cache
jQuery(document).ready(function() {
(function() {
    var flicker = 0;
    var flickerImg = jQuery('#flicker img');

    jQuery('#flicker').hover(
        function() {
           flicker = setInterval(function() {
               if (jQuery('#flicker img.active').next('img').length > 0) {
                   jQuery('#flicker img.active').removeClass('active').next('img').addClass('active');
                   } else {
                   flickerImg.removeClass('active');
                   flickerImg.first().addClass('active');
               } 
           }, 200);
         }, 
         function() {
           clearInterval(flicker);
         }
     ); 
})();
});
ready
With Cache & Link Element
jQuery(document).ready(function() {
(function() {
    var flicker = 0;
    var flickerImg = jQuery('#flicker img');
    var flickerLink = jQuery('#flicker');    

    flickerLink.hover(
        function() {
           flicker = setInterval(function() {
               if (jQuery('#flicker img.active').next('img').length > 0) {
                   jQuery('#flicker img.active').removeClass('active').next('img').addClass('active');
                   } else {
                   flickerImg.removeClass('active');
                   flickerImg.first().addClass('active');
               } 
           }, 200);
         }, 
         function() {
           clearInterval(flicker);
         }
     ); 
})();
});
ready

Revisions

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