master
<canvas id='master' width='100' height='100'></canvas>
<canvas id='pid' width='100' height='100'></canvas>pid1
<canvas id='di' width='100' height='100'></canvas>di1
<canvas id='pid2' width='100' height='100'></canvas>pid2
<canvas id='di2' width='100' height='100'></canvas>di2
var master = document.getElementById('master');
var masterctx = master.getContext('2d');
var pid = document.getElementById('pid').getContext('2d');
var di = document.getElementById('di').getContext('2d');
var pid2 = document.getElementById('pid2').getContext('2d');
var di2 = document.getElementById('di2').getContext('2d');
masterctx.fillRect(0,0,50,50);
masterctx.fillStyle = "red";
masterctx.fillRect(50,50,100,100);
di.drawImage(master,0,0);
let imgData = masterctx.getImageData(0,0,100,100);
pid.putImageData(imgData,0,0);
di2.drawImage(master,25,0,50,100,25,0,50,100);
let imgDatas = masterctx.getImageData(25,0,50,100);
pid2.putImageData(imgDatas,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 di2 canvas | |
PutImageData half master into pid2 canvas |
Test name | Executions per second |
---|---|
DrawImage whole master into di canvas | 746384.9 Ops/sec |
PutImageData whole master into pid canvas | 20951.7 Ops/sec |
DrawImage half master into di2 canvas | 509058.5 Ops/sec |
PutImageData half master into pid2 canvas | 32562.8 Ops/sec |
Let's dive into the Benchmark Definition and explain what's being tested, compared, and their pros and cons.
Benchmark Definition
The benchmark is designed to compare two approaches for rendering an image on a web page:
di.drawImage(master, 0, 0)
.getImageData
to extract pixel data from the master image and then applying it to another canvas using putImageData
.Comparison Points
The benchmark compares four individual test cases:
di
using di.drawImage(master, 0, 0)
.pid
using putImageData
.di2
using di2.drawImage(master, 25, 0, 50, 100, 25, 0, 50, 100)
.pid2
using putImageData
.Pros and Cons
Here's a brief overview of each approach:
In general, PutImageData is often preferred when rendering large images or performing complex transformations, while DrawImage is suitable for simpler use cases.
Libraries and Special Features
There are no notable libraries mentioned in the benchmark definition. However, the use of getContext('2d')
suggests that it's utilizing the 2D drawing context API, which is a standard feature in most modern browsers.
No special JavaScript features or syntax are mentioned in this benchmark.