translate3d vs background-color

JavaScript performance comparison

Revision 122 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="elem" style="position: absolute; background-color:white; width:10px; height:10px;"></div>
<div id="elem2" style="position: absolute; background-color:black; width:10px; height:10px;"></div>
<script>
  var elem = document.getElementById("elem");
  var style = elem.style;
  var elem2 = document.getElementById("elem2");
  var style2 = elem2.style;
  var elem2j = $("#elem2");
</script>
    

Preparation code output

<div id="elem" style="position: absolute; background-color:white; width:10px; height:10px;"></div> <div id="elem2" style="position: absolute; background-color:black; 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
background-color
var high = false;

for (var i = 200; i--;) {
  if (high) {
    style2.background = 'black';
    high = false;
  } else {
    style2.background = 'white';
    high = true;
  }
}
pending…
translate3d
var high = false;

for (var i = 200; i--;) {
  if (high) {
    style2.WebkitTransform = 'translate3d(0, 0, 0)';
    high = false;
  } else {
    style2.WebkitTransform = 'translate3d(1000px, 0, 0)';
    high = true;
  }
}
pending…
translate
var high = false;

for (var i = 200; i--;) {
  if (high) {
    style2.WebkitTransform = 'translate(0, 0)';
    high = false;
  } else {
    style2.WebkitTransform = 'translate(1000px, 0)';
    high = true;
  }
}
pending…
var high = false;

for (var i = 200; i--;) {
  if (high) {
    style2.background = '#000000';
    high = false;
  } else {
    style2.background = '#ffffff';
    high = true;
  }
}
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