canvas-clear

JavaScript performance comparison

Revision 22 of this test case created

Info

Different methods for clearing the canvas.

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>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/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");
pending…
fillRect
for (var i = 0; i < 100; i++) {
 ctx.fillStyle = 'rgba(255,255,255,1)';
 ctx.fillRect(0, 0, 500, 500);
}
pending…
set width
ctx.globalCompositeOperation = 'source-over';
ctx.fillStyle = 'rgba(0,0,0,1)';
for (var i = 0; i < 100; i++) {
 ctx.fillRect(0, 0, 1, 1);
 c.width = c.width;
}
var p = ctx.getImageData(0, 0, 1, 1);
if (p.data[3] != 0) throw ("set width does not clear");
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. Here’s a list of current revisions for this page:

0 comments

Add a comment