Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
drawimage vs putimagedata 3b
(version: 0)
Comparing performance of:
drawImage vs putImageData
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<canvas id="canvas" width="1400" height="1400"></canvas>
Script Preparation code:
var canvas = document.getElementById('canvas'); var ctx = canvas.getContext("2d"); var cacheG = document.createElement('canvas'); var cacheD = cacheG.getContext('2d'); cacheG.width = 1200; cacheG.height = 1200; cacheD.beginPath(); cacheD.fillStyle = '#000'; cacheD.arc(600, 600, 600, 0, Math.PI * 2, true); cacheD.fill(); var d = cacheD.getImageData(0,0,1200,1200)
Tests:
drawImage
ctx.drawImage(cacheG, 6, 6);
putImageData
ctx.putImageData(d, 6, 6);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
drawImage
putImageData
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0
Browser/OS:
Firefox 144 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
drawImage
48886.0 Ops/sec
putImageData
163.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **Benchmark Definition JSON** The benchmark definition represents two microbenchmarks: `drawImage` and `putImageData`. These tests aim to measure the performance difference between drawing an image using `drawImage()` and putting image data into context using `putImageData()`. **Script Preparation Code** The script preparation code creates a temporary canvas element (`cacheG`) with a size of 1200x1200. It then sets up a 2D drawing context on this canvas (`cacheD`). The code draws a black circle on the canvas using the `fillStyle` and `arc()` methods. **Html Preparation Code** The HTML preparation code includes an `<canvas>` element with a width and height of 1400 pixels, which will be used as the container for the benchmark. **Individual Test Cases** There are two test cases: 1. **drawImage**: This test case measures the performance of drawing an image using `ctx.drawImage(cacheG, 6, 6);`. The image is drawn at position (6, 6) on the main canvas. 2. **putImageData**: This test case measures the performance of putting image data into context using `ctx.putImageData(d, 6, 6);`. The image data (`d`) is obtained from the temporary canvas (`cacheD`) and drawn at position (6, 6) on the main canvas. **Library: Canvas** Both tests use the HTML5 Canvas API, which provides a way to draw graphics in web pages. The Canvas API allows developers to create images, manipulate pixel data, and perform various drawing operations using JavaScript. In this benchmark, the `Canvas` library is used to: * Create temporary canvases (`cacheG`) for image data * Draw shapes (in this case, a circle) on these canvases using 2D drawing contexts **Special JS Feature/Syntax:** The tests use a special JavaScript feature called **`ImageData` objects**, which represent pixel data in the form of a 1D array. The `ImageData` object is used to store the pixel data from the temporary canvas (`cacheD`) and pass it to the `putImageData()` method for drawing. **Pros and Cons:** The pros of using `drawImage()` over `putImageData()` are: * **Faster performance**: Drawing an image using `drawImage()` is generally faster than putting image data into context. * **Less overhead**: `drawImage()` has less overhead compared to `putImageData()`, as it doesn't require manipulating pixel data. However, the cons of using `drawImage()` over `putImageData()` are: * **More complex code**: Using `drawImage()` can lead to more complex code, as developers need to handle image loading and caching. * **Less control**: With `drawImage()`, developers have less control over the drawing process compared to `putImageData()`. On the other hand, `putImageData()` provides: * **More control**: Developers have fine-grained control over pixel data manipulation using `putImageData()`. * **Flexibility**: `putImageData()` can be used for more complex graphics and animations. **Alternatives:** Other alternatives to testing performance differences between `drawImage()` and `putImageData()` include: * Using WebGL or WebGPU for 3D rendering * Testing the performance of different image compression algorithms * Measuring the performance of other drawing operations, such as `fillRect()`, `strokeText()`, etc. Keep in mind that the choice of test case and benchmarking approach depends on the specific use case and requirements.
Related benchmarks:
drawimage vs putimagedata 2
drawimage vs putimagedata 3
Image vs ImageBitmap vs canvas with context2d
Image vs canvas with 2d
Comments
Confirm delete:
Do you really want to delete benchmark?