Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
save/restore vs manual
(version: 0)
Comparing performance of:
save/restore vs manual
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<canvas id="canvasOne" width="400" height="400"></canvas> <canvas id="canvasTwo" width="400" height="400"></canvas>
Script Preparation code:
var canvasOne = document.getElementById("canvasOne"); var ctxOne = canvasOne.getContext("2d"); var canvasTwo = document.getElementById("canvasTwo"); var ctxTwo = canvasTwo.getContext("2d");
Tests:
save/restore
ctxOne.fillStyle = 'rgba(255, 255, 255, 0.3)'; ctxOne.fillRect(0, 0, 400, 400); ctxOne.save(); ctxOne.beginPath(); ctxOne.moveTo(Math.random() * 400, Math.random() * 400); ctxOne.lineTo(Math.random() * 400, Math.random() * 400); ctxOne.shadowBlur = 20; ctxOne.shadowOffsetX = 10; ctxOne.shadowOffsetY = 10; ctxOne.shadowColor = '#8E44AD'; ctxOne.strokeStyle = '#8E44AD'; ctxOne.lineWidth = 1; ctxOne.stroke(); ctxOne.restore(); ctxOne.beginPath(); ctxOne.fillStyle = '#52BE80'; ctxOne.arc(Math.random * 400, Math.random * 400, 20, 0, Math.PI * 2, true); ctxOne.fill();
manual
ctxTwo.fillStyle = 'rgba(255, 255, 255, 0.3)'; ctxTwo.fillRect(0, 0, 400, 400); ctxTwo.beginPath(); ctxTwo.moveTo(Math.random() * 400, Math.random() * 400); ctxTwo.lineTo(Math.random() * 400, Math.random() * 400); ctxTwo.shadowBlur = 20; ctxTwo.shadowOffsetX = 10; ctxTwo.shadowOffsetY = 10; ctxTwo.shadowColor = '#8E44AD'; ctxTwo.strokeStyle = '#8E44AD'; ctxTwo.lineWidth = 1; ctxTwo.stroke(); ctxTwo.shadowBlur = 0; ctxTwo.shadowOffsetX = 0; ctxTwo.shadowOffsetY = 0; ctxTwo.shadowColor = 'rgba(0, 0, 0, 0)'; ctxTwo.beginPath(); ctxTwo.fillStyle = '#52BE80'; ctxTwo.arc(Math.random() * 400, Math.random() * 400, 20, 0, Math.PI * 2, true); ctxTwo.fill();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
save/restore
manual
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 world of JavaScript microbenchmarks and explore what's being tested in this specific benchmark. **Benchmark Overview** The provided JSON represents a benchmark that compares two approaches: using `ctx.save()` and `ctx.restore()` (save/restore) versus manual adjustments to the canvas context (`ctx`). **Options Compared** Two options are being compared: 1. **Save/Restore**: This approach uses `ctx.save()` to save the current state of the canvas context, creates a new state with `ctx.beginPath()`, applies transformations (e.g., moving, stroking), and then restores the original state with `ctx.restore()`. The transformed context is then used for drawing. 2. **Manual**: This approach eliminates the need for saving and restoring by applying all transformations directly to the canvas context without creating a new state. **Pros and Cons of Each Approach** **Save/Restore:** Pros: * Easier to manage complex transformations, as each transformation creates a new state that can be easily restored. * Can be more efficient in terms of CPU usage, as the browser can optimize the use of saved states. Cons: * May incur additional overhead due to saving and restoring the context, which could impact performance. * Limited control over transformation order and dependencies. **Manual:** Pros: * Provides direct access to all transformations without any intermediaries, potentially reducing overhead. * Allows for fine-grained control over transformation order and dependencies. Cons: * Requires more manual management of complex transformations, which can lead to errors or inconsistencies if not implemented correctly. **Library Usage** The benchmark uses the 2D drawing context (`ctx`) provided by the browser's canvas API. The `ctx` object is used for drawing operations, such as filling shapes and stroking paths. **Special JS Features/Syntax** This benchmark does not explicitly use any special JavaScript features or syntax, but it relies on the browser's engine to optimize performance. However, some older browsers might have different rendering behaviors or performance characteristics that could affect the benchmark results. **Other Alternatives** To test similar scenarios, you could create benchmarks for other approaches, such as: * Using a dedicated graphics library like WebGL or Three.js * Employing GPU-accelerated rendering techniques (e.g., WebGPU) * Exploring different canvas context configurations (e.g., `requestAnimationFrame()` vs. synchronous drawing) When creating your own benchmark, consider using a similar structure to the provided JSON, including: 1. A clear description of the test scenario and goals. 2. Relevant preparation code for setting up the testing environment. 3. Test cases that cover different aspects of the system or feature being tested. 4. Results format (e.g., JSON) for easy analysis and comparison. Keep in mind that benchmarking can be complex, and results may vary depending on factors like hardware, software configurations, and system load.
Related benchmarks:
save/restore vs manual - shadow
rgb vs rgba (1 & 0.5) vs hex canvas
save&restore vs manual
Canvas clearing performance v3
Comments
Confirm delete:
Do you really want to delete benchmark?