translate vs position left/top vs css margin left/top (v56)

Revision 56 of this benchmark created by dstereo 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>

Setup

var x = 0,
        t = '';

Test runner

Ready to run.

Testing in
TestOps/sec
translate
for (var i = 200; i--;) {
  x = i * 5;
  t = 'translate(' + x + 'px, ' + x + 'px)';
  style.WebkitTransform = t;
  style.MozTransform = t;
  style.OTransform = t;
  style.msTransform = t;
  style.transform = t;
}
ready
translate X/Y
for (var i = 200; i--;) {
  x = i * 5;
  t = 'translateX(' + x + 'px) translateY(' + x + 'px)';
  style.WebkitTransform = t;
  style.MozTransform = t;
  style.OTransform = t;
  style.msTransform = t;
  style.transform = t;
}
ready
position left/top
for (var i = 200; i--;) {
  x = i * 5;
  t = x + 'px';
  style.left = t;
  style.top = t;
}
ready
margin left/top
for (var i = 200; i--;) {
  x = i * 5;
  t = x + 'px';
  style.marginLeft = t;
  style.marginTop = t;
}
ready

Revisions

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