JSFiddle - React, Tailwind, and code Playground

by Drath

HTML

<p>Testing performance of canvas drawing from image or drawing from another canvas (pre-rendering).</p>

<canvas id="test" width="400" height="400"></canvas>
<canvas id="test2" width="400" height="400"></canvas>

JavaScript

canvas = document.getElementById('test');
ctx = canvas.getContext('2d');
canvas2 = document.getElementById('test2');
ctx2 = canvas2.getContext('2d');
tiles = new Image();

tiles.onload = function() {
    ctx2.drawImage(tiles,0,0);
    
    //Draw on to the canvas from Image 
    //23ms (Chrome 19, Windows 7 64-Bit)
    //18ms (Firefox 13, Windows 7 64-Bit)
    console.time("Test");
    for(var i = 0; i <= 5000; i++) {
        ctx.drawImage(tiles,0,0);
    }
    console.timeEnd("Test");
    
    //Draw on to the canvas from another canvas
    //17ms (Chrome 19, Windows 7 64-Bit)
    //24ms (Firefox 13, Windows 7 64-Bit)
    console.time("Test2");
    for(var i = 0; i <= 5000; i++) {
        ctx.drawImage(ctx2.canvas,0,0);
    }
    console.timeEnd("Test2");
}
    
tiles.src =...