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

Revision 77 of this benchmark created 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


    style.WebkitTransform = "none";
    style.MozTransform = "none";
    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;
  style.WebkitTransform = 'translate3d(' + x + 'px, ' + y + 'px, 0px)';
  style.MozTransform = 'translate3d(' + x + 'px, ' + y + 'px, 0px)';
  style.OTransform = 'translate3d(' + x + 'px, ' + y + 'px, 0px)';
  style.transform = 'translate3d(' + x + 'px, ' + y + 'px, 0px)';
}
ready
translateX/Y
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  style.WebkitTransform = 'translateX(' + x + 'px) translateY(' + y + 'px)';
  style.MozTransform = 'translateX(' + x + 'px) translateY(' + y + 'px)';
  style.OTransform = 'translateX(' + x + 'px) translateY(' + y + 'px)';
  style.transform = '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;
  var transform = 'translate(' + x + 'px, ' + y + 'px)';
  style.WebkitTransform = 'translate(' + x + 'px, ' + y + 'px)';
  style.MozTransform = 'translate(' + x + 'px, ' + y + 'px)';
  style.OTransform = 'translate(' + x + 'px, ' + y + 'px)';
  style.transform = 'translate(' + x + 'px, ' + y + 'px)';
}
ready

Revisions

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