translate3d vs translate XY vs css left/top vs matrix2d/3d

JavaScript performance comparison

Revision 64 of this test case created

Preparation code

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

var transformProperties = [ 'transform', 'MozTransform = transform', 'WebkitTransform', 'OTransform', 'msTransform'],
    transformProperty;

for (var key in transformProperties) {
    var value = transformProperties[key];

    if (document.documentElement.style[value] !== undefined){
        transformProperty = value;
        break;
    }
}

</script>
 

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
translate3d
var x = y = 0;
for (var i = 100; i--;) {
 x = i;
 y = i * 5;
 var transform = 'translate3d(' + x + 'px, ' + y + 'px, 0)';
 style[transformProperty] = transform;

}
pending…
translateX/Y
var x = y = 0;
for (var i = 100; i--;) {
 x = i;
 y = i * 5;
 var transform = 'translateX(' + x + 'px) translateY(' + y + 'px)';
 style[transformProperty] = transform;

}
pending…
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';
}
pending…
maxtrix
var x = 0,
    y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  var transform = 'matrix(1,0,0,1,' + x + ',' + y + ')';
  style[transformProperty] = transform;

}
pending…
matrix3d
var x = 0,
    y = 0;
for (var i = 100; i--;) {
  x = i;
  y = i * 5;
  var transform = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,' + x + ',' + y + ',0,1)';
  style[transformProperty] = transform;

}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment