translate3d vs translate2d vs translate XY vs css left/top vs scrollTop/scrollLeft vs matrix3d vs matrix (v107)

Revision 107 of this benchmark created by Bryan Crow on


Description

All cases with pre-calculated vendor prefixes (now including IE)

Preparation HTML

<div id="scrollTranslator" style="width:96000000px; 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;
  var setTransform = (style.WebkitTransform) ? function(transform) {
    style.WebkitTransform = transform;
  } : (style.MozTransform) ? function(transform) {
    style.MozTransform = transform;
  } : (style.msTransform) ? function(transform) {
    style.msTransform = transform;
  } : function(transform) {
    style.OTransform = transform;
  };
</script>

Teardown


      setTransform('none');
      style.left = '0px';
      style.top = '0px';
      translator.scrollLeft = 0;
      translator.scrollTop = 0;
  

Test runner

Ready to run.

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

Revisions

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