translate3d vs translate XY vs css left/top vs scrollleft (v114)

Revision 114 of this benchmark created on


Preparation HTML

<div id="elem" style="position: absolute; background:#ccc; width:10px; height:10px; transition:translate"></div>
<script>
  var elem = document.getElementById("elem");
  var style = elem.style;
</script>

<div id="elem2" style="overflow:scroll;width:300px;height:500px;">
<div class="content" style="position: absolute; background:#ccc; width:80px; height:250px; margin:20px;">
</div>
<div class="content" style="position: absolute; background:#ccc; width:80px; height:250px; margin:20px;">
</div>
<div class="content" style="position: absolute; background:#ccc; width:80px; height:250px; margin:20px;">
</div>
<div class="content" style="position: absolute; background:#ccc; width:80px; height:250px; margin:20px;">
</div>
<div class="content" style="position: absolute; background:#ccc; width:80px; height:250px; margin:20px;">
</div>
<div class="content" style="position: absolute; background:#ccc; width:80px; height:250px; margin:20px;">
</div>
<div class="content" style="position: absolute; background:#ccc; width:80px; height:250px; margin:20px;">
</div>
<div class="content" style="position: absolute; background:#ccc; width:80px; height:250px; margin:20px;">
</div>


</div>
<script>
  var elem2 = document.getElementById("elem2");
</script>

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, 0)';

}
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)';

}
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
Scroll left
var x = y = 0;
for (var i = 100; i--;) {
 x = i;
 y = i * 5;
 elem2.scrollLeft = x + 'px';
 elem2.scrollTop = y + 'px';
}
ready
translate x/y + z
var x = y = 0;
for (var i = 100; i--;) {
 x = i;
 y = i * 5;

 style.WebkitTransform = 'translateX(' + x + 'px) translateY(' + y + 'px)' + ' translateZ(0)';

}
ready
translate + z
var x = y = 0;
for (var i = 100; i--;) {
 x = i;
 y = i * 5;

 style.WebkitTransform = 'translate(' + x + 'px, ' + y + 'px)' + ' translateZ(0)';

}
ready

Revisions

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