translate3d vs translate XY vs css left/top vs scrollleft

JavaScript performance comparison

Revision 115 of this test case created by

Preparation code

<div  id="elem2" style="width: 300px; overflow-x:scroll;white-space:nowarp; height:200px">
<div id="elem" style=" position:relative; width: 800px ; background:black;  height:100px; background-color:balck">
    
</div>
</div>
<script>
  var elem = document.getElementById("elem");
  var style= elem.style;
  var elem2 = document.getElementById("elem2");
 

</script>
    

Preparation code output

<div id="elem2" style="width: 300px; overflow-x:scroll;white-space:nowarp; height:200px"> <div id="elem" style=" position:relative; width: 800px ; background:black; height:100px; background-color:balck"> </div> </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 = y = 0;
for (var i = 100; i--;) {
 x = i;
 y = i * 5;

 style.WebkitTransform = 'translate3d(' + x + 'px, ' + y + 'px, 0)';

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

 style.WebkitTransform = 'translateX(' + x + 'px) translateY(' + y + 'px)';

}
pending…
css left/top
var x = y = 0;
for (var i = 100; i--;) {
 x = i;

 style.left = x + 'px';

}
pending…
Scroll left
var x = y = 0;
for (var i = 100; i--;) {
 x = i;

 elem2.scrollLeft=i; 

}
pending…
translate x/y + z
var x = y = 0;
for (var i = 100; i--;) {
 x = i;
 y = 0;

 style.WebkitTransform = 'translateX(' + x + 'px) translateY(' + y + 'px)' + ' translateZ(0)';

}
pending…
translate + z
var x = y = 0;
for (var i = 100; i--;) {
 x = i;
 y = 0;

 style.WebkitTransform = 'translate(' + x + 'px, ' + y + 'px)' + ' translateZ(0)';

}
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