canvas-spritesheets (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var numFrames = 20;
  var sWidth = 64;
  var sHeight = 64;
  var c = document.createElement('canvas');
  c.height = sHeight;
  c.width = sWidth * numFrames;
  var ctx = c.getContext('2d');
  ctx.fillRect(0, 0, c.width, c.height);

  var c2 = document.createElement('canvas');
  c2.width = 512;
  c2.height = 512;
  var ctx2 = c2.getContext('2d');

  var frames = [];
  var index = 0;
  for (var i = 0; i < numFrames; i++) {
    var f = document.createElement('canvas');
    f.width = sWidth;
    f.height = sHeight;
    var fctx = f.getContext('2d');
    fctx.globalCompositeOperation = 'copy';
    fctx.drawImage(c, 0, 0, sWidth, sHeight, index, 0, sWidth, sHeight);
    frames.push(f);

    index += sWidth;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
clipping
for (i = 0, index = 0; i < numFrames; i++, index += sWidth) {
  ctx2.drawImage(c, 0, 0, sWidth, sHeight, 0, 0, sWidth, sHeight);
}
ready
cached frames
for (i = 0; i < numFrames; i++) {
  ctx2.drawImage(frames[i], 0, 0);
}
ready

Revisions

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