scrollTop profiling

JavaScript performance comparison

Test case created by scrollTop profiling

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div class="wrapper" style="overflow:auto;">
  <div class="inner">
  </div>
</div>
<script>
Benchmark.prototype.setup = function() {
    var innerBox = document.querySelector('.inner'),
        wrapperBox = document.querySelector('.wrapper'),
        $wrapperBox = $(wrapperBox)
         text = 'Lorem ipsum <br>',
        wrapperHeight = 200,
        i, innerHeight;
   
    for (var i = 8; i--;) {
      text += text;
    }
   
    innerBox.innerHTML = text;
    wrapperBox.style.height = wrapperHeight + 'px';
    innerHeight = innerBox.offsetHeight;
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
pure
for (i = 1000; i--;) {
  wrapperBox.scrollTop = (Math.random() * innerHeight | 0);
}
pending…
jQuery
for (i = 1000; i--;) {
  $wrapperBox.scrollTop((Math.random() * innerHeight | 0));
}
pending…

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

Compare results of other browsers

0 comments

Add a comment