HTML Preparation code:
AخA
 
1
<canvas id="c" width="800" height="300"></canvas>
Script Preparation code:
 
$c = document.getElementById('c');
$ctx = $c.getContext('2d');
$ctx.clearRect(0, 0, 800, 300);
$px = $ctx.createImageData(1, 1);
$pxls = [];
for (var i=0; i<10000; ++i) $pxls.push({
   x: Math.random() * 800 << 0,
   y: Math.random() * 300 << 0,
   r: Math.random() * 255 << 0,
   g: Math.random() * 255 << 0,
   b: Math.random() * 255 << 0,
   a: Math.random() * 128 << 0 + 128
});
$i = 0;
Tests:
  • fillRect/concat

     
    for (var i=500;i--;){
    var px = $pxls[$i++ % 10000];
    $ctx.fillStyle = 'rgba(' + px.r + ',' + px.g + ',' + px.b + ',' + (px.a / 255) + ')';
    $ctx.fillRect(px.x, px.y, 1, 1);
    }
  • fillRect/optimized further

     
    const alphmult = 1 / 255
    for (let i=500;--i;){
    const px = $pxls[++$i % 10000];
    $ctx.fillStyle = `rgba(${px.r},${px.g},${px.b},${px.a * alphmult})`;
    $ctx.fillRect(px.x, px.y, 1, 1);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    fillRect/concat
    fillRect/optimized further

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4029.3 Safari/537.36
Chrome 81 on Windows
View result in a separate tab
Test name Executions per second
fillRect/concat 785.5 Ops/sec
fillRect/optimized further 794.3 Ops/sec