translate3d vs translate XY vs css left/top vs scrollleft

JavaScript performance comparison

Revision 128 of this test case created by raina77ow

Preparation code

<div id="cont" style="background:#ccc; width:100px; height:100px;overflow:auto;">
</div>

      
<script>
Benchmark.prototype.setup = function() {
  var elem = document.createElement('div');
  elem.id = 'elem';
  elem.style = 'position:absolute;height:1000px;width:50px;background-color:#FF0;';
  document.getElementById('cont').appendChild(elem);
  var xform = 'transform';
      ['webkit', 'Moz', 'O', 'ms'].every(function (prefix) {
          var e = prefix + 'Transform';
          if (typeof elem.style[e] !== 'undefined') {
              xform = e;
              return false;
          }
          return true;
      });

};

Benchmark.prototype.teardown = function() {
  document.getElementById('cont').innerHTML = '';

};
</script>

Preparation code output

<div id="cont" style="background:#ccc; width:100px; height:100px;overflow:auto;"> </div>

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
translateY
for (var i = 1; i <= 100; i++) {
  elem.style[xform] = 'translateY(' + (-i) + 'px) translateZ(0px)';
}
pending…
Scroll left
for (var i = 1; i <= 100; i++) {
  elem.scrollTop = -i;
}
pending…
Scroll using css top
for (var i = 1; i <= 100; i++) {
  elem.style.top = i;
}
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