translate3d vs translate vs css left/top vs css margin

JavaScript performance comparison

Revision 120 of this test case created by XPoli

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;
</script>
    

Preparation code output

<div id="elem" style="position: absolute; background:#ccc; width:10px; height:10px;"></div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/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;
}
pending…
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;
}
pending…
left
var x = 0,
    t = '';

for (var i = 200; i--;) {
  x = i * 5;
  style.left = x + 'px';
  elem._width = elem.offsetWidth;
}
pending…
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;
}
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.

0 Comments