Canvas Draw Image vs fill rect

JavaScript performance comparison

Revision 21 of this test case created

Preparation code

<canvas id="c1" width="300" height="300"></canvas>
<canvas id="c2" width="300" height="300"></canvas>
 
<script>
Benchmark.prototype.setup = function() {
    var c1 = document.getElementById('c1');
    var c2 = document.getElementById('c1');
    var ctx1 = c1.getContext('2d');
    var ctx2 = c2.getContext('2d');
    var grad1 = ctx1.createLinearGradient(0, 0, 0, 300);
    ctx1.fillStyle = grad1;
    var grad2 = ctx2.createLinearGradient(0, 0, 0, 300);
    ctx2.fillStyle = grad2;
    grad1.addColorStop(0, "hsla(" + 40 + ",100%,50%,.6)");
    grad1.addColorStop(1, "hsla(" + 90 + ",100%,50%,.5)");
    grad2.addColorStop(0, "hsla(" + 40 + ",100%,50%,.6)");
    grad2.addColorStop(1, "hsla(" + 90 + ",100%,50%,.5)");
    ctx2.fillRect(0, 0, 300, 300);
    ctx1.drawImage(ctx2.canvas, 0, 0, 300, 300, 0, 0, 300, 300);
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Draw Image
ctx1.drawImage(ctx2.canvas, 0, 0, 300, 300, 0, 0, 300, 300);
pending…
Fill Rect
ctx1.fillRect(0, 0, 300, 300);
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