canvas loops

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code

<script>
  // Create a 35x35 Canvas block.
  var canvasNode = document.createElement('canvas');
  canvasNode.width = "35";
  canvasNode.height = "35"
  
  // We must put this node into the body, otherwise
  // Safari Windows does not report correctly.
  canvasNode.style.display = 'none';
  document.body.appendChild(canvasNode);
  var ctx = canvasNode.getContext('2d');
  
  // draw a black letter 'O', 32px Arial.
  ctx.textBaseline = "top";
  ctx.font = "32px Arial";
  ctx.fillStyle = "black";
  ctx.strokeStyle = "black";
  
  ctx.fillText("O", 0, 0);
</script>
    

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
stored data
var imageData = ctx.getImageData(0, 0, canvasNode.width, canvasNode.height)

for (var x = 8; x <= 32; x++) {
 for (var y = 1; y <= 32; y++) {

  var idx = (x + y * imageData.width) * 4;
  var alpha = imageData.data[idx + 3]

  if (alpha != 255 && alpha != 0) {
   return true; // font-smoothing must be on.
  }
 }
}
pending…
data at point
for (var j = 8; j <= 32; j++) {
 for (var i = 1; i <= 32; i++) {

  var imageData = ctx.getImageData(i, j, 1, 1).data;
  var alpha = imageData[3];

  if (alpha != 255 && alpha != 0) {
   return true; // font-smoothing must be on.
  }
 }

}
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