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

Revision 23 of this benchmark created by Justin on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
translate3d
var x = y = 0;
for (var i = 100, j = Math.random(); i--; j++) {
  x = j;
  y = j * 5;

  st.WebkitTransform = 'translate3d(' + x + 'px, ' + y + 'px, 0)';

}
ready
translate3d (round)
var x = y = 0;
for (var i = 100, j = Math.random(); i--; j++) {
  x = j;
  y = j * 5;

  st.WebkitTransform = 'translate3d(' + (x|0) + 'px, ' + (y|0) + 'px, 0)';

}
ready
translateX/Y
var x = y = 0;
for (var i = 100, j = Math.random(); i--; j++) {
  x = j;
  y = j * 5;

  st.WebkitTransform = 'translateX(' + x + 'px) translateY(' + y + 'px)';

}
ready
translateX/Y (round)
var x = y = 0;
for (var i = 100, j = Math.random(); i--; j++) {
  x = j;
  y = j * 5;

  st.WebkitTransform = 'translateX(' + (x|0) + 'px) translateY(' + (y|0) + 'px)';

}
ready
css left/top
var x = y = 0;
for (var i = 100, j = Math.random(); i--; j++) {
  x = j;
  y = j * 5;

  st.left = x + 'px';
  st.top = y + 'px';
}
ready
css left/top (round)
var x = y = 0;
for (var i = 100, j = Math.random(); i--; j++) {
  x = j;
  y = j * 5;

  st.left = (x|0) + 'px';
  st.top = (y|0) + 'px';
}
ready

Revisions

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