Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Canvas roundrect perf
(version: 0)
Comparing performance of:
Own roundRect vs roundRect
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<canvas id="canvas1" width="512" height="512"></canvas> <style> canvas { border: 1px solid black; } </style> <script> var canvas = document.getElementById('canvas1'); var ctx = canvas.getContext('2d'); </script>
Tests:
Own roundRect
function roundRect(canvas, x, y, w, h, r) { if (w < 2 * r) r = Math.round(w / 2); if (h < 2 * r) r = Math.round(h / 2); canvas.beginPath(); canvas.moveTo(x + r, y); canvas.arcTo(x + w, y, x + w, y + h, r); canvas.arcTo(x + w, y + h, x, y + h, r); canvas.arcTo(x, y + h, x, y, r); canvas.arcTo(x, y, x + w, y, r); canvas.closePath(); } roundRect(ctx, 10, 10, 200, 100, 20);
roundRect
ctx.roundRect(10, 10, 200, 100, 20);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Own roundRect
roundRect
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0
Browser/OS:
Firefox 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Own roundRect
674102.3 Ops/sec
roundRect
1496398.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the Benchmark Definition and test cases. **Benchmark Definition:** The provided JSON defines two benchmarking scenarios for measuring the performance of JavaScript code that draws a rounded rectangle using the 2D drawing context (`ctx`) on a canvas element. **Options Compared:** 1. **Native `roundRect` method**: The first benchmark definition uses the native `roundRect` method available on the `ctx` object, which is implemented in the browser's rendering engine. 2. **Custom `roundRect` function**: The second benchmark definition defines a custom `roundRect` function that takes five arguments (`x`, `y`, `w`, `h`, and `r`) to calculate and draw the rounded rectangle. **Pros and Cons of Each Approach:** 1. **Native `roundRect` method**: * Pros: Likely faster and more optimized since it's implemented in the browser's rendering engine. * Cons: May not be available on older browsers or with specific canvas features enabled. 2. **Custom `roundRect` function**: * Pros: Can provide more control over the drawing process, allowing for potential optimizations or edge cases that might be missed by the native implementation. * Cons: May introduce overhead due to the additional function call and calculation. **Other Considerations:** * The use of `Math.round()` to calculate the rounded radius (`r`) can lead to integer precision issues, potentially affecting performance. * Using a custom function instead of the native method might require additional setup or dependencies. **Library Usage:** None mentioned in this benchmark definition. **Special JS Features/Syntax:** None explicitly mentioned. However, it's worth noting that the use of `var` for variable declarations is an older syntax (ES5). Modern JavaScript would typically use `let` or `const` instead. **Alternative Approaches:** * To measure the performance of other drawing functions or methods on the canvas element, additional benchmark definitions could be added. * Using a different rendering engine or browser to compare performance might be necessary to accurately evaluate the native implementation's speed. * Adding more test cases with varying input sizes, shapes, or complexity can help identify potential bottlenecks and optimize the custom `roundRect` function. By analyzing these aspects of the benchmark definition, developers can better understand the trade-offs between using the native `roundRect` method versus implementing their own custom function.
Related benchmarks:
rgb vs rgba (1 & 0.5) vs hex canvas
RGB vs RGBa vs HSL vs Hex using Canvas v2
Canvas roundrect perf comparison check
Roundrect perf comparison check
Comments
Confirm delete:
Do you really want to delete benchmark?