<canvas id='master' width='100' height='100'></canvas>
<canvas id='pid' width='100' height='100'></canvas>
<canvas id='di' width='100' height='100'></canvas>
var master = document.getElementById('master');
var masterctx = master.getContext('2d');
var pid = document.getElementById('pid').getContext('2d');
var di = document.getElementById('di').getContext('2d');
masterctx.fillRect(0,0,50,50);
masterctx.fillStyle = "red";
masterctx.fillRect(50,50,100,100);
var imgDataFull = masterctx.getImageData(0,0,100,100);
var imgDataHalf = masterctx.getImageData(25,0,75,100);
di.drawImage(master,0,0);
pid.putImageData(imgDataFull,0,0);
di.drawImage(master,25,0,50,100,25,0,50,100);
pid.putImageData(imgDataHalf,25,0);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
DrawImage whole master into di canvas | |
PutImageData whole master into pid canvas | |
DrawImage half master into di canvas | |
PutImageData half master into pid canvas |
Test name | Executions per second |
---|---|
DrawImage whole master into di canvas | 527600.0 Ops/sec |
PutImageData whole master into pid canvas | 18132.3 Ops/sec |
DrawImage half master into di canvas | 495002.5 Ops/sec |
PutImageData half master into pid canvas | 16859.6 Ops/sec |
Let's break down the provided benchmark and explain what is being tested, compared, and the pros and cons of each approach.
Benchmark Definition
The benchmark measures the performance difference between two approaches:
drawImage
function to draw a portion of an image (the entire "master" canvas) onto another canvas (di
). The original image data is not retrieved or copied explicitly.putImageData
function to copy and paste an image (either the full "master" canvas or a portion of it) from one canvas (pid
) into another (di
). There are two variations:di
.di
.Options being compared
The benchmark compares the performance of these four approaches:
Pros and Cons of each approach:
Library and purpose
In this benchmark, the relevant libraries are:
Special JS feature or syntax
This benchmark does not explicitly use any special JavaScript features or syntax that are not part of the standard language. However, it relies on the Canvas API's drawImage
, putImageData
, and getContext
methods, which might require knowledge of advanced web development concepts.
Other alternatives
If you're interested in exploring alternative approaches, consider:
These alternatives might be suitable for specific use cases, such as 3D graphics rendering, game development, or high-performance image processing.