canvas-clear (v38)

Revision 38 of this benchmark created on


Description

Different methods for clearing the canvas.

Preparation HTML

<script>
  var c = document.createElement('canvas');
  c.width = c.height = 500;
  var ctx = c.getContext('2d');
  ctx.fillStyle = 'rgba(0,0,0,1)';
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
clearRect
ctx.globalCompositeOperation = 'source-over';
ctx.fillStyle = 'rgba(0,0,0,1)';
for (var i = 0; i < 100; i++) {
 ctx.fillRect(0, 0, 1, 1);
 ctx.clearRect(0, 0, 500, 500);
}
var p = ctx.getImageData(0, 0, 1, 1);

if (p.data[3] != 0) throw ("clearRect does not clear");
ready
fillRect
for (var i = 0; i < 100; i++) {
 ctx.globalCompositeOperation = 'source-over';
 ctx.fillStyle = 'rgba(0,0,0,1)';
 ctx.fillRect(0, 0, 1, 1);
 ctx.globalCompositeOperation = 'copy';
 ctx.fillStyle = 'rgba(0,0,0,0)';
 ctx.fillRect(0, 0, 500, 500);
}
var p = ctx.getImageData(0, 0, 1, 1);

if (p.data[3] != 0) throw ("fillRect does not clear");
ready
set width
 
ready

Revisions

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