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

Revision 38 of this benchmark created on


Description

Added support for multiple browsers

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;
  function setTransform(value){
   if (st.transform!=undefined) st.transform = value;
   else if (st.WebkitTransform!=undefined) st.WebkitTransform = value;
   else if (st.MozTransform!=undefined) st.MozTransform = value;
   else if (st.OTransform!=undefined) st.OTransform = value;
   else if (st.msTransform!=undefined) st.msTransform = value;
}
</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;

 setTransform( 'translate3d(' + x + 'px, ' + y + 'px, 0)' );

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

 setTransform( transform = 'translateX(' + x + 'px) translateY(' + y + 'px)' );

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

 setTransform( 'translate(' + x + 'px ' + y + 'px)' );

}
ready

Revisions

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