translate3d vs translate vs css left/top vs css margin (v120)

Revision 120 of this benchmark created by XPoli 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 = 0,
    t = '';

for (var i = 200; i--;) {
  x = i * 5;
  style.WebkitTransform = style.MozTransform = style.OTransform = style.msTransform = style.transform = 'translate3d(' + x + 'px, 0, 0)';
  elem._width = elem.offsetWidth;
}
ready
translate
var x = 0,
    t = '';

for (var i = 200; i--;) {
  x = i * 5;
  style.WebkitTransform = style.MozTransform = style.OTransform = style.msTransform = style.transform = 'translate(' + x + 'px, 0)';
  elem._width = elem.offsetWidth;
}
ready
left
var x = 0,
    t = '';

for (var i = 200; i--;) {
  x = i * 5;
  style.left = x + 'px';
  elem._width = elem.offsetWidth;
}
ready
translateX
var x = 0,
    t = '';

for (var i = 200; i--;) {
  x = i * 5;
  style.WebkitTransform = style.MozTransform = style.OTransform = style.msTransform = style.transform = 'translateX(' + x + 'px)';
  elem._width = elem.offsetWidth;
}
ready

Revisions

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