canvas-clear

JavaScript performance comparison

Revision 60 of this test case created by Bodo Thiesen

Preparation code

<script>
  var c = document.createElement('canvas');
  c.width = c.height = 500;
  var ctx = c.getContext('2d');
  ctx.fillStyle = 'rgba(0,0,0,1)';
</script>
      
<script>
Benchmark.prototype.setup = function() {
  function draw_scene(ctx);
    ctx.save();
    ctx.globalCompositeOperation = 'source-over';
    ctx.fillStyle = 'rgba(0,0,0,1)';
    ctx.fillRect(0, 0, 1, 1);
    ctx.restore();
  }

};
</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
clearRect
// Code snippet 5
for (var i = 0; i < 100; i++) {
  draw_scene(ctx);
  ctx.clearRect(0, 0, 500, 500);
}
var p = ctx.getImageData(0, 0, 1, 1);
if (p.data[3] != 0) throw ("clearRect does not clear");
pending…
fillRect
// Code snippet 4
ctx.globalCompositeOperation = 'copy';
ctx.fillStyle = 'rgba(0,0,0,0)';
for (var i = 0; i < 100; i++) {
  draw_scene(ctx);
  ctx.fillRect(0, 0, 500, 500);
}
var p = ctx.getImageData(0, 0, 1, 1);
if (p.data[3] != 0) throw ("fillRect does not clear");
pending…
set width
// Code snippet 6
for (var i = 0; i < 100; i++) {
  draw_scene(ctx);
  c.width = c.width;
}
var p = ctx.getImageData(0, 0, 1, 1);
if (p.data[3] != 0) throw ("set width does not clear");
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments