Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Image vs ImageBitmap vs canvas with context2d
(version: 0)
Testing draw calls using a raw Image versus an ImageBitmap vs canvas
Comparing performance of:
Image vs ImageBitmap vs canvas
Created:
4 years ago
by:
Guest
Jump to the latest result
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; let canvas3 = document.createElement('canvas'); canvas3.width = 640; canvas3.height = 480; var ctx = canvas.getContext('2d'); var ctx2 = canvas2.getContext('2d'); var ctx3 = canvas2.getContext('2d'); var cv = document.createElement('canvas'); cv.width = 700; cv.height = 700; var cvx = cv.getContext('2d'); img.addEventListener('load', function() { cvx.drawImage(img,0,0); 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);
canvas
if (doneLoading) cvx.drawImage(cv,0,0);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Image
ImageBitmap
canvas
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0
Browser/OS:
Firefox 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Image
577810.6 Ops/sec
ImageBitmap
529525.9 Ops/sec
canvas
5576.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the details of this benchmark. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmark that compares the performance of three different approaches to draw an image: 1. Using a raw Image 2. Using an ImageBitmap 3. Using a canvas element with context 2D The benchmark is designed to test the number of executions per second (ExecutionsPerSecond) for each approach. **Options Compared** The three options being compared are: * Raw Image: This method uses the native `drawImage()` function on the `img` object. * ImageBitmap: This method uses the `createImageBitmap()` function and then draws the image using the `drawImage()` function on an ImageBitmap object. * Canvas with context 2D: This method creates a new canvas element, gets its 2D drawing context, and draws the image using the `drawImage()` function. **Pros and Cons of Each Approach** 1. **Raw Image**: This approach is simple and efficient, but it may not be suitable for large images or images with complex pixel data. * Pros: Fast and lightweight * Cons: May not handle large images or complex pixel data well 2. **ImageBitmap**: This approach uses the `createImageBitmap()` function to convert the image to a more convenient format, which can improve performance for some use cases. * Pros: Can handle larger images and more complex pixel data than raw Image * Cons: May introduce overhead due to the conversion process 3. **Canvas with context 2D**: This approach uses the canvas element to draw the image, which provides a high degree of control over the rendering process. * Pros: Provides fine-grained control over rendering and can handle complex pixel data well * Cons: May be slower than raw Image or ImageBitmap due to the overhead of creating and manipulating the canvas element **Library Used** The `createImageBitmap()` function is used in the ImageBitmap test case. This function converts an image into a bitmap format that can be manipulated as a 2D array of pixels. **Special JavaScript Feature/Syntax** There is no special JavaScript feature or syntax being tested in this benchmark. The code is standard JavaScript and uses only native functions and features. **Other Alternatives** If you wanted to test different approaches, you could consider the following alternatives: * Using WebGL or WebGPU: These APIs provide high-performance rendering capabilities and can be used to render images. * Using a library like Pixi.js or Fabric.js: These libraries provide a higher-level API for working with graphics and canvas elements, which can simplify some aspects of rendering. * Testing different image formats: You could test using different image formats, such as WebP or AVIF, to see how they perform in the benchmark. Overall, this benchmark provides a good starting point for comparing the performance of different approaches to drawing images in JavaScript. By testing each approach with and without the ImageBitmap conversion, you can get a better understanding of their relative performance characteristics.
Related benchmarks:
Image vs ImageBitmap with context2d
Image vs ImageBitmap vs cv with context2d
Image vs canvas with 2d
Image vs canvas with webgl2d
Comments
Confirm delete:
Do you really want to delete benchmark?