Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36
Chrome 92
Windows
Desktop
3 years ago
Test name Executions per second
Canvas 522894.0 Ops/sec
Offscreen 534176.3 Ops/sec
Canvas font 1818508.6 Ops/sec
Offscreen font 5847189.5 Ops/sec
Canvas textBaseline 5072035.5 Ops/sec
Offscreen textBaseline 4831063.5 Ops/sec
Canvas textAlign 5104876.0 Ops/sec
Offscreen textAlign 4724849.5 Ops/sec
Script Preparation code:
x
 
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var offscreenCanvas = new OffscreenCanvas(0, 0);
var offscreenContext = offscreenCanvas.getContext('2d');
Tests:
  • Canvas

     
    context.measureText('M');
  • Offscreen

     
    offscreenContext.measureText('M');
  • Canvas font

     
    context.font = 'bold 48px serif';
  • Offscreen font

     
    offscreenContext.font = 'bold 48px serif';
  • Canvas textBaseline

     
    context.textBaseline = "hanging";
  • Offscreen textBaseline

     
    offscreenContext.textBaseline = "hanging";
  • Canvas textAlign

     
    context.textAlign = "center";
  • Offscreen textAlign

     
    offscreenContext.textAlign = "center";