Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Canvas paths performance -fixed
(version: 0)
Comparing performance of:
Direct with beginpath vs Direct fillrect
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<canvas align="center" id="canvas" width="800" height="800"></canvas>
Script Preparation code:
var ctx = document.getElementById('canvas').getContext('2d'); ctx.fillStyle = 'rgba(0,1,0,1)'; var rects = [] for (var i = 0; i < 50; i++) { var width = 5 + i * 5; var height = 7 + i * 3; var path = new Path2D(); path.rect(0, 0, width, height); var rect = { x: i, y: i, width: width, height: height, cachedPath: path }; rects.push(rect); } ctx.clearRect(0, 0, 500, 500);
Tests:
Direct with beginpath
ctx.beginPath(); for (var i = 0; i < rects.length; i++) { var rect = rects[i]; ctx.rect(rect.x, rect.y, rect.width, rect.height); } ctx.fill();
Direct fillrect
for (var i = 0; i < rects.length; i++) { var rect = rects[i]; ctx.fillRect(rect.x, rect.y, rect.width, rect.height); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Direct with beginpath
Direct fillrect
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0
Browser/OS:
Firefox 135 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Direct with beginpath
141416.8 Ops/sec
Direct fillrect
25008.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the provided benchmark and explain what is tested, compared options, pros/cons, library usage, and special JavaScript features. **Benchmark Definition** The benchmark measures the performance of two different approaches to draw rectangles on a canvas: 1. Using `ctx.beginPath()` followed by drawing each rectangle individually. 2. Using `ctx.fillRect()` directly for each rectangle. **Options Compared** The two options compared are: 1. **`ctx.beginPath() + ctx.rect()`**: This approach involves calling `beginPath()` before drawing each rectangle, and then using `rect()` to draw the rectangle. After drawing all rectangles, `fill()` is called. 2. **`ctx.fillRect()` directly**: This approach involves calling `fillRect()` directly for each rectangle without setting up a path. **Pros/Cons of Each Approach** 1. **`ctx.beginPath() + ctx.rect()`**: * Pros: allows for more control over the drawing process, can be used with other canvas operations like `stroke()` or `clip()`. * Cons: may incur overhead due to the need to call `beginPath()` and `fill()` separately. 2. **`ctx.fillRect()` directly**: * Pros: faster and more lightweight, as it avoids the overhead of setting up a path. * Cons: less control over the drawing process, may not be suitable for complex shapes or paths. **Library Usage** There is no library used in this benchmark. It only relies on the native Canvas API provided by modern web browsers. **Special JavaScript Features** There are no special JavaScript features mentioned in the benchmark definition or test cases. However, it's worth noting that the use of `var` declarations and older JavaScript syntax (e.g., `for` loops with explicit type declaration) may not be suitable for all modern JavaScript environments. **Other Alternatives** If you're interested in exploring alternative approaches, here are a few examples: * Using `CanvasRenderingContext2D.isPointInPath()` to check if a point is inside the current path before drawing. * Utilizing WebGL or WebGPU to accelerate canvas rendering (although this would likely require significant changes to the benchmark code). * Investigating other rendering engines like React Native, Electron, or desktop frameworks that provide their own APIs for drawing graphics. Keep in mind that these alternatives might not be directly comparable to the original benchmark, and may require more significant modifications to the test cases.
Related benchmarks:
Canvas paths performance
rgb vs rgba (1 & 0.5) vs hex canvas
Canvas paths performance without alpha
Canvas paths performance v94
Comments
Confirm delete:
Do you really want to delete benchmark?