canvas-blitting-full

JavaScript performance comparison

Test case created by Ilmari

Preparation code

<script>
  var c = document.createElement('canvas');
  c.width = c.height = 256;
  var ctx = c.getContext('2d');
  
  var framebuffer = ctx.getImageData(0, 0, 256, 256);
</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
fillRect
ctx.clearRect(0, 0, 256, 256);
for (var j = 0; j < 256; j++) {
 for (var i = 0; i < 256; i++) {
  ctx.fillRect(i, j, 1, 1);
 }
}
pending…
putImageData
var px = framebuffer.data;
for (var j = 0; j < 256; j++) {
 for (var i = 0; i < 256; i++) {
  var off = (j * 256 + i) * 4;
  px[off] = 0;
  px[off + 1] = 0;
  px[off + 2] = 0;
  px[off + 3] = 255;
 }
}
ctx.putImageData(framebuffer, 0, 0);
pending…
gradient fillRect
ctx.clearRect(0, 0, 256, 256);
for (var j = 0; j < 256; j++) {
 for (var i = 0; i < 256; i++) {
  ctx.fillStyle = 'rgba(' + i + ',0,' + j + ',1)';
  ctx.fillRect(i, j, 1, 1);
 }
}
pending…
gradient putImageData
var px = framebuffer.data;
for (var j = 0; j < 256; j++) {
 for (var i = 0; i < 256; i++) {
  var off = (j * 256 + i) * 4;
  px[off] = i;
  px[off + 1] = 0;
  px[off + 2] = j;
  px[off + 3] = 255;
 }
}
ctx.putImageData(framebuffer, 0, 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