drawImage vs CanvasPattern (v3)

Revision 3 of this benchmark created by Bruno Garcia on


Description

For drawing sprites, how does fillRect() with a CanvasPattern compare to drawImage?

Preparation HTML

<canvas id="screen"></canvas>
<script>
  var ctx = document.getElementById("screen").getContext("2d");
  var patternRepeat, patternNoRepeat;
  var image = document.createElement("img");
  image.onload = function() {
   patternNoRepeat = ctx.createPattern(image, "no-repeat");
   patternRepeat = ctx.createPattern(image, "repeat");
  };
  image.src = "http://icons.iconarchive.com/icons/ph03nyx/super-mario/48/Retro-Mushroom-1UP-2-icon.png";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Image
ctx.drawImage(image, 0, 0);
ready
No repeat
ctx.fillStyle = patternNoRepeat;
ctx.fillRect(0, 0, image.width, image.height);
ready
Repeat
ctx.fillStyle = patternRepeat;
ctx.fillRect(0, 0, image.width, image.height);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.