translate3d vs translate XY vs css left/top (v59)

Revision 59 of this benchmark created on


Preparation HTML

<div id="elem" style="position: absolute; background:#ccc; width:10px; height:10px;"></div>
<script>
  var elem = document.getElementById("elem");
  var style = elem.style;
</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)';
  elem._width = elem.offsetWidth; // force reflow
}
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)';
  elem._width = elem.offsetWidth; // force reflow

}
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';
  elem._width = elem.offsetWidth; // force reflow
}
ready
css height/width
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  style.width = x + 'px';
  style.height = y + 'px';
  elem._width = elem.offsetWidth; // force reflow
}
ready
matrix
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;

  style.WebkitTransform = 'matrix(1,0,0,1,' + x + ',' + y + ')';
  elem._width = elem.offsetWidth; // force reflow

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

  style.WebkitTransform = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,' + x + ',' + y + ',0,1)';
  elem._width = elem.offsetWidth; // force reflow

}
ready
translateY
// async test
var x = y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;

  style.WebkitTransform = 'translateY(' + y + 'px)';
  elem._width = elem.offsetWidth; // force reflow

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

  style.WebkitTransform = 'translate3d(0, ' + y + 'px, 0)';
  elem._width = elem.offsetWidth; // force reflow
}
ready

Revisions

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