canvasclear (v6)

Revision 6 of this benchmark created by Bill Baxter on


Preparation HTML

<canvas id="canvas1" width="500" height="500"></canvas>
<script>
  var can = document.getElementById('canvas1');
  var ctx = can.getContext('2d');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
setting width
ctx.strokeRect(10, 10, 50, 50);
can.width = can.width;
ready
clearing non-transformed canvas
ctx.strokeRect(10, 10, 50, 50);
ctx.clearRect(0, 0, can.width, can.height);
ready
clearing transformed canvas
ctx.strokeRect(10, 10, 50, 50);
// I have lots of transforms right now
ctx.save();
ctx.setTransform(1, 0, 0, 1, 0, 0);
// Will always clear the right space
ctx.clearRect(0, 0, can.width, can.height);
ctx.restore();
// Still have my old transforms
ready
fillRect instead
ctx.strokeRect(10, 10, 50, 50);
// I have lots of transforms right now
ctx.save();
ctx.setTransform(1, 0, 0, 1, 0, 0);
// Will always clear the right space
ctx.fillStyle = 'rgba(0,0,0,0)';
ctx.globalCompositeOperation = 'source-in';
ctx.fillRect(0, 0, can.width, can.height);
ctx.restore();
// Still have my old transforms
ready

Revisions

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