canvas clearRect vs width

JavaScript performance comparison

Revision 5 of this test case created by Jocelyn LECOMTE

Preparation code

<canvas id="testcanvas" width="512" height="512">
</canvas>
      
<script>
Benchmark.prototype.setup = function() {
  var canvas = document.getElementById('testcanvas');
  var context = canvas.getContext('2d');

};
</script>

Preparation code output

<canvas id="testcanvas" width="512" height="512"> </canvas>

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
simple clearRect on the whole canvas
context.clearRect(0, 0, 512, 512);
pending…
width hack
canvas.width = canvas.width;
pending…
simple clearrect partial
context.clearRect(0, 0, 256, 256);
context.clearRect(0, 256, 256, 256);
context.clearRect(256, 0, 256, 256);
context.clearRect(256, 256, 256, 256);
pending…
clearRect with saveState
context.save();
context.setTransform(1, 0, 0, 1, 0, 0);
context.clearRect(0, 0, 512, 512);
context.restore();
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