Image vs ImageBitmap with context2d
Testing draw calls using a raw Image versus an ImageBitmap
Date tested:
one year ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.44
Test name
Executions per second
Image
1512944.0 Ops/sec
ImageBitmap
123538.8 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var img = new Image(); var imageBitmap; var doneLoading = false; let canvas = document.createElement('canvas'); canvas.width = 640; canvas.height = 480; let canvas2 = document.createElement('canvas'); canvas2.width = 640; canvas2.height = 480; var ctx = canvas.getContext('2d'); var ctx2 = canvas2.getContext('2d'); img.addEventListener('load', function() { Promise.all([ createImageBitmap(img) ]).then(function(images) { imageBitmap = images[0]; doneLoading = true; }, false); }); img.src = 'https://1.bp.blogspot.com/-52MtzD0GfX0/WvP52CL1WjI/AAAAAAAAOVw/_OpK4JHeWK01d-7IiZ6vzojYGhXqLRXrACLcBGAs/s1600/EMxediL.jpg';
Tests:
Image
if (doneLoading) ctx.drawImage(img,0,0);
ImageBitmap
if (doneLoading) ctx2.drawImage(imageBitmap,0,0);
Open this result on MeasureThat.net