<canvas id="canvas" width="1400" height="1400"></canvas>
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,12,12)
ctx.drawImage(cacheG, 6, 6);
ctx.putImageData(d, 6, 6);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
drawImage | |
putImageData |
Test name | Executions per second |
---|---|
drawImage | 26298.2 Ops/sec |
putImageData | 228439.6 Ops/sec |
Benchmark Explanation
The provided benchmark tests the performance of two methods to draw an image on a canvas: drawImage
and putImageData
. The test is designed to compare the execution speed of these two methods.
Options Being Compared
The two options being compared are:
Pros and Cons
putImageData
for large images or complex transformations.Library Used
In this benchmark, the putImageData
method uses a library called getImageData
, which is not explicitly mentioned in the benchmark JSON. However, based on its usage, it appears to be a utility function that returns an image data object, which can be used with putImageData
.
Special JS Feature or Syntax
The benchmark uses no special JavaScript features or syntax other than standard ECMAScript.
Other Alternatives
If you need to draw images on a canvas, there are several alternative methods you could use:
drawImage
or as an input for another library.In summary, the benchmark is testing the performance of two popular methods for drawing images on a canvas: drawImage
and putImageData
. The choice between these methods depends on your specific use case and requirements.