Canvas Draw Image vs fill rect

JavaScript performance comparison

Revision 24 of this test case created

Preparation code

<canvas id="myCanvas" width="600" height="400"></canvas>
<img id="myImg" />
<script>
Benchmark.prototype.setup = function() {
    var canvas = document.getElementById('myCanvas');
    var ctx = canvas.getContext('2d');
    var img = document.getElementById('myImg');
    img.onload = function() {
       canvas.height = img.height;
       canvas.width = img.width;
       ctx.fillStyle = ctx.createPattern(img, 'no-repeat');
    }
    img.src = "http://www.clipartbest.com/cliparts/pT5/65z/pT565zETB.png";
    ctx.mozImageSmoothingEnabled = false;
    //ctx.scale(4, 4);
   
};
</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
ctx.drawImage(img, 0, 0, img.width, img.height);
pending…
Fill Rect
ctx.fillRect(0, 0, img.width, img.height);
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