Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
drawImage with scaling vs context scaling
(version: 0)
Comparing performance of:
drawImage scaling vs context scaling
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<canvas id="canvas1" width="50" height="50"></canvas> <br> <canvas id="canvas2" width="500" height="500"></canvas> <canvas id="canvas3" width="500" height="500"></canvas>
Script Preparation code:
var canvas1 = document.getElementById("canvas1") var ctx1 = canvas1.getContext("2d"); var canvas2 = document.getElementById("canvas2") var ctx2 = canvas2.getContext("2d"); var canvas3 = document.getElementById("canvas3") var ctx3 = canvas3.getContext("2d"); ctx1.fillStyle = "rgb(10,80,80)"; ctx1.fillRect(0,0,50,50); ctx1.fillStyle = "rgb(80,180,180)"; ctx1.fillRect(4,4,42,42); ctx3.scale(10, 10);
Tests:
drawImage scaling
ctx2.drawImage(canvas1, 0, 0, 50, 50, 0, 0, 500, 500);
context scaling
ctx3.drawImage(canvas1, 0, 0, 50, 50);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
drawImage scaling
context scaling
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the Benchmark Definition and test cases. **Benchmark Definition** The benchmark measures two different approaches to draw an image on a canvas: `drawImage` with scaling and context scaling (also known as "stretching" or "resizing"). The `Script Preparation Code` section of the benchmark setup creates three canvases (`canvas1`, `canvas2`, and `canvas3`) using JavaScript's 2D drawing API. The third canvas is scaled by a factor of 10x10 using the `scale()` method. **Options being compared** Two options are being compared: 1. **`drawImage` with scaling**: This approach uses the `drawImage()` method to draw an image on a new canvas, specifying the x and y coordinates, width, height, and source rectangle (which is used to scale the image). 2. **Context scaling** (`scale()` method): This approach uses the `scale()` method to directly modify the canvas's transformation matrix, which allows for scaling without needing to draw an intermediate image. **Pros and Cons** Here are some pros and cons of each approach: * **`drawImage` with scaling**: + Pros: More intuitive and straightforward approach. Can be easily adapted to other drawing operations. + Cons: May lead to slower performance due to the overhead of creating a new canvas and using the `drawImage()` method. * **Context scaling (`scale()` method)**: + Pros: Optimized for performance, as it uses the canvas's internal transformation matrix. Can be faster than the `drawImage` approach. + Cons: May require more complex code to manage the scaling transformation. **Library usage** In this benchmark, no specific JavaScript library is used beyond the standard 2D drawing API (Canvas API). However, some modern browsers may use optimized implementations of these APIs that rely on underlying libraries or frameworks. **Special JS features/syntax** This benchmark does not appear to utilize any special JavaScript features or syntax, such as async/await, promises, or ES6+ features like template literals or arrow functions. **Alternative approaches** Other alternatives for drawing images on canvases include: 1. **Pixel manipulation**: Directly manipulating pixel data using the `getImageData()` and `putImageData()` methods. 2. **WebGL**: Using WebGL to render graphics directly onto the canvas. 3. **Canvas spritesheets**: Loading multiple images as a single sprite sheet and using the `drawImage()` method to draw individual frames. These alternative approaches can offer different trade-offs in terms of performance, complexity, and flexibility compared to the `drawImage` with scaling and context scaling methods used in this benchmark.
Related benchmarks:
Image vs ImageBitmap vs cv with context2d
Image vs ImageBitmap vs canvas with context2d
Image vs canvas with 2d
Drawing pre-scaled image vs scaling (same size of result image)
Comments
Confirm delete:
Do you really want to delete benchmark?