draw Image base64 vs url vs blob

JavaScript performance comparison

Revision 27 of this test case created by

Preparation code

<img id="img" src="https://lh3.googleusercontent.com/-v9Hd_uz3oDA/VGn7n0Ox5gI/AAAAAAAAAD8/RiMsgsj3_1o/w600-h800-no/07f5ffe6ca7eb5d3c2b8d3bc8c.jpg"/>
<script>
var image_url, base64_jpeg, base64_png, blob_url, blob;
var img = new Image();
img.onload = function(){
var c = document.createElement('canvas');
c.width = img.width;
c.height = img.height;
var ctx = c.getContext("2d");
ctx.drawImage(img, 0, 0);

image_url = img.src;
base64_jpeg = c.toDataURL('image/jpeg', 0.9);
base64_png = c.toDataURL("image/png");
}

img.crossOrigin = "Anonymous";
img.src = "https://lh3.googleusercontent.com/-v9Hd_uz3oDA/VGn7n0Ox5gI/AAAAAAAAAD8/RiMsgsj3_1o/w600-h800-no/07f5ffe6ca7eb5d3c2b8d3bc8c.jpg";

var xhr = new XMLHttpRequest();
xhr.open( "GET", img.src, true );
xhr.responseType = "arraybuffer";
xhr.onload = function( e ) {
    var arrayBufferView = new Uint8Array( this.response );
    blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
    var urlCreator = window.URL || window.webkitURL;
    blob_url = urlCreator.createObjectURL( blob );
};

xhr.send();
</script>
    

Preparation code output

<img id="img" src="https://lh3.googleusercontent.com/-v9Hd_uz3oDA/VGn7n0Ox5gI/AAAAAAAAAD8/RiMsgsj3_1o/w600-h800-no/07f5ffe6ca7eb5d3c2b8d3bc8c.jpg"/>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
image from url
// async test
var img = new Image();
img.onload = function() {
  deferred.resolve();
}
img.src = image_url;
pending…
image from base64 jpeg
// async test
var img = new Image();
img.onload = function() {
  deferred.resolve();
}
img.src = base64_jpeg;
pending…
image from base64 png
// async test
var img = new Image();
img.onload = function() {
  deferred.resolve();
}
img.src = base64_png;
pending…
image from blob_url
// async test
var img = new Image();
img.onload = function() {
  deferred.resolve();
}
img.src = blob_url;
pending…
image from blob
// async test
var img = new Image();
img.onload = function() {
  deferred.resolve();
}
var urlCreator = window.URL || window.webkitURL;
img.src = urlCreator.createObjectURL(blob);
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.

0 Comments