window.scrollTo vs jquery.scrollTop (v4)

Revision 4 of this benchmark created by Oleksandr Kelepko on


Preparation HTML

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

Setup

var $Win = $(window);
    var y = 1, inc = 10,
      max = Math.max(1000, $(document).height() - $(window).height()) | 0;
    
    function nextY() {
      if (y === max || y === 0) inc = -inc;
      y += inc;
      return y;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
window.scrollTo
// async test
setTimeout(function() {
  window.scrollTo(0, nextY());
  deferred.resolve();
}, 0);
ready
jquery.scrollTop
// async test
setTimeout(function() {
  $Win.scrollTop(nextY());
  deferred.resolve();
}, 0);
ready
window.scrollTo x 2
// async test
setTimeout(function() {
  window.scrollTo(0, nextY());
  window.scrollTo(0, 300);
  deferred.resolve();
}, 0);
ready
jquery.scrollTop x 2
// async test
setTimeout(function() {
  $Win.scrollTop(nextY());
  $Win.scrollTop(300);
  deferred.resolve();
}, 0);
ready

Revisions

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