var img = new Image();
var imageBitmap;
var doneLoading = false;
let canvas = document.createElement('canvas');
canvas.width = 640;
canvas.height = 480;
let canvas2 = document.createElement('canvas');
canvas2.width = 640;
canvas2.height = 480;
let canvas3 = document.createElement('canvas');
canvas3.width = 640;
canvas3.height = 480;
var ctx = canvas.getContext('2d');
var ctx2 = canvas2.getContext('2d');
var ctx3 = canvas2.getContext('2d');
var cv = document.createElement('canvas');
cv.width = 700;
cv.height = 700;
var cvx = cv.getContext('2d');
img.addEventListener('load', function() {
cvx.drawImage(img,0,0);
});
img.src = 'https://1.bp.blogspot.com/-52MtzD0GfX0/WvP52CL1WjI/AAAAAAAAOVw/_OpK4JHeWK01d-7IiZ6vzojYGhXqLRXrACLcBGAs/s1600/EMxediL.jpg';
if (doneLoading)
ctx.drawImage(img,0,0);
if (doneLoading)
ctx3.drawImage(cv,0,0);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Image | |
Image CV |
Test name | Executions per second |
---|---|
Image | 26770318.0 Ops/sec |
Image CV | 26754494.0 Ops/sec |
Benchmark Overview
The provided benchmark measures the performance of two approaches: drawing an image directly to a canvas element (Raw Image) and using the ImageBitmap
API with the same image, compared to another approach that uses a separate canvas element (cv
) to draw the image.
Options Compared
ImageBitmap
API to create a bitmap representation of the image, which can then be drawn onto another canvas element.cv
) to draw the image, similar to the ImageBitmap
approach.Library Usage
The ImageBitmap
API is used in both the Raw Image and Image CV approaches. This library provides a way to create a bitmap representation of an image, which can then be manipulated and drawn onto another canvas element.
Special JS Features/Syntax
None mentioned in this specific benchmark.
Benchmark Preparation Code Analysis
The provided script preparation code creates multiple canvas elements and assigns them context objects (ctx
, ctx2
, ctx3
, cvx
). It also sets up an image loading event listener that draws the image onto each of these canvases when it loads. The benchmark only tests two scenarios:
ImageBitmap
to create a bitmap representation of the image and drawing it onto another canvas element (Image CV)Other Considerations
When implementing this benchmark, consider the following factors:
Alternative Benchmarks
If you're looking to explore other approaches, consider benchmarks that focus on: