Changing Canvas State

JavaScript performance comparison

Revision 3 of this test case created by David Gillen

Preparation code

<canvas id="c" width="640" height="480"></canvas>
<script>
  var canvas = document.getElementById('c');
  var context = canvas.getContext('2d');
  
  var GAP = 10;
  var COLOR1 = 'red';
  var COLOR2 = 'blue';
  var STRIPES = 20;
</script>
      
<script>
Benchmark.prototype.setup = function() {
  context.clearRect(0, 0, canvas.width, canvas.height);
  

};
</script>

Preparation code output

<canvas id="c" width="640" height="480"></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
serially
for (var i = 0; i < STRIPES; i++) {
  context.fillStyle = (i % 2 ? COLOR1 : COLOR2);
  context.fillRect(i * GAP, 0, GAP, 480);
}
pending…
two passes
context.fillStyle = COLOR2;
for (var i = 0; i < STRIPES/2; i++) {
  context.fillRect((i*2) * GAP, 0, GAP, 480);
}
context.fillStyle = COLOR1;
for (var i = 0; i < STRIPES/2; i++) {
  context.fillRect((i*2+1) * GAP, 0, GAP, 480);
}
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