Canvas.toDataURL image type performance (v25)

Revision 25 of this benchmark created on


Description

Tests toDataURL image types with a large canvas

Preparation HTML

<canvas id="canvas" width="1280" height="720" style="width:1280px; height:720px;">
</canvas>

<script>
c = document.getElementById("canvas");
ctx = c.getContext("2d");
cpa = ctx.createImageData(1280, 720);
Math.round(Math.random() * 255);
for (var i = 0; i < 1280 * 720; i++) {
  cpa.data[i * 4 + 0] = 1;
  cpa.data[i * 4 + 1] = 100;
  cpa.data[i * 4 + 2] = 200;
  cpa.data[i * 4 + 3] = 255;
}
ctx.putImageData(cpa, 0, 0);
HTMLCanvasElement.prototype.toBlobSync = function(type, quality) {
    var dataURL = this.toDataURL(type, quality),
        binary = atob( dataURL.substr( dataURL.indexOf(',') + 1 ) ),
        i = binary.length,
        view = new Uint8Array(i);

    while (i--) {
        view[i] = binary.charCodeAt(i);
    }

    return view;
};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
getImageData
ctx.getImageData(0, 0, c.width, c.height).data
ready
toBlobSync image/jpeg high
c.toBlobSync("image/jpeg", 0.9);
ready
toBlobSync image/jpeg low
c.toBlobSync("image/jpeg", 0.7);
ready
toBlobSync image/png
c.toBlobSync("image/png");
ready

Revisions

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