drawImage from different sources (v43)

Revision 43 of this benchmark created on


Preparation HTML

<canvas id="cnv" width="320" height="240">
</canvas>
<img id="img" src="http://mozilla.org/media/img/firefox/template/header-logo-inverse.png" style="display: none" />

Setup

function createCanvas(w, h) {
    var canvas = document.createElement('canvas');
    canvas.setAttribute('width', w);
    canvas.setAttribute('height', h);
    return canvas;
  }
  
  // globals
  var g_ctx = document.getElementById('cnv').getContext('2d');
  var g_img = document.getElementById('img');
  var g_offscreenCanvas = createCanvas(320, 240);
  var ww = g_img.width;
  var hh = g_img.height;
  var wwHalf = ww * 0.5;
  var hhHalf = hh * 0.5;
  var cw = g_ctx.canvas.width;
  var ch = g_ctx.canvas.height;
  
  var g_octx = g_offscreenCanvas.getContext('2d');

Test runner

Ready to run.

Testing in
TestOps/sec
img
g_ctx.drawImage(g_img, 0, 0, 180, 70, 0, 0, 180, 70);
ready
not-in-dom canvas
g_octx.drawImage(g_img, 0, 0);
ready
img basic
g_ctx.drawImage(g_img, 0, 0);
ready
img w/ lookups
g_ctx.drawImage(g_img, 0, 0, g_img.width, g_img.height, 0, 0, g_img.width, g_img.height);
ready
img basic w/ stretching
g_ctx.drawImage(g_img, 0, 0, 200, 200);
ready
img basic w/ shrinking
g_ctx.drawImage(g_img, 0, 0, 50, 50);
ready
img w/ stretching
g_ctx.drawImage(g_img, 0, 0, ww, hh, 0, 0, cw, ch);
ready
img w/ shrinking
g_ctx.drawImage(g_img, 0, 0, ww, hh, 0, 0, wwHalf, hhHalf);
ready
img w/ width & height lookup & stretching
g_ctx.drawImage(g_img, 0, 0, 180, 70, 0, 0, g_img.width, g_img.height);
ready
img w/ vars & stretching
g_ctx.drawImage(g_img, 0, 0, 180, 70, 0, 0, ww, hh);
ready

Revisions

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