with func or not

JavaScript performance comparison

Test case created by Jay Z

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
    

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
With Outside Function Call
$(function() {
  triga.css("display", "none");
  $(window).scroll(function() {
    scrollMenu($(this).scrollTop())
  });
});

function scrollMenu(down) {
  var up = $('#horiz_line').offset().top + $('#horiz_line').height() + 25,
      triga = $('.trigger');
  (down > up) ? triga.fadeIn('fast') : triga.fadeOut('fast')
}
pending…
Native inner function
$(function() {
  var up = $('#horiz_line').offset().top + $('#horiz_line').height() + 25,
      triga = $('.trigger');
  triga.css("display", "none");
  $(window).scroll(function() {
    var down = $(this).scrollTop();
    (down > up) ? triga.fadeIn('fast') : triga.fadeOut('fast')
  });
});
pending…
With built-in var func
$(function() {
  $(window).scroll(function() {
    scrollMenu($(this).scrollTop())
  });
  var scrollMenu = function(down) {
      var triga = $('.trigger'),
          up = $('#horiz_line').offset().top + $('#horiz_line').height() + 25;
      (down > up) ? triga.fadeIn('fast') : triga.fadeOut('fast')
      }
});
pending…
up pre-defined
// Variable Up Takes up The Global Namespace. Is it better to pre-define it OR have it inside the scroll Menu anonymous func and get calculated each time the function is run? 
$(function() {
  var up = $('#horiz_line').offset().top + $('#horiz_line').height() + 25;
  $(window).scroll(function() {
    scrollMenu(up, $(this).scrollTop())
  });
  var scrollMenu = function(up, down) {
      var triga = $('.trigger');
      (down > up) ? triga.fadeIn('fast') : triga.fadeOut('fast')
      }
});
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.

0 Comments