translate3d vs translate2d vs translate XY vs css left/top vs scrollTop/scrollLeft (v103)

Revision 103 of this benchmark created by for length on


Preparation HTML

<div id="scrollTranslator" style="width:200px; height:200px; overflow: hidden"><div id="elem" style="position: relative; background:#ccc; width:1000px; height:1000px;"></div></div>
<script>
  var translator = document.getElementById("scrollTranslator");
  var elem = document.getElementById("elem");
  var style = elem.style;
</script>

Teardown


      if (style.WebkitTransform) {
        style.WebkitTransform = "none";
      } else if (style.MozTransform) {
        style.MozTransform = "none";
      } else {
        style.OTransform = "none";
      }
      style.left = '0px';
      style.top = '0px';
  

Test runner

Ready to run.

Testing in
TestOps/sec
translate3d
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  var transform = 'translate3d(' + x + 'px, 0, 0)';
  style.WebkitTransform = transform;
 
}
ready
translateX/Y
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  var transform = 'translateX(' + x + 'px)';
  
    style.WebkitTransform = transform;
  
}
ready
css left/top
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  style.left = x + 'px';
}
ready
translate2d
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  var transform = 'translate(' + x + 'px, 0)';
  
    style.WebkitTransform = transform;
  
}
ready
scrollTop/scrollLeft
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  translator.scrollLeft = x;
}
ready

Revisions

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