Skip to content

Commit

Permalink
add font setter benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
chearon committed Dec 29, 2024
1 parent 8346512 commit f22223c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions benchmarks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ function done (benchmark, times, start, isAsync) {

// node-canvas

function fontName () {
return String.fromCharCode(0x61 + Math.floor(Math.random() * 26)) +
String.fromCharCode(0x61 + Math.floor(Math.random() * 26)) +
String.fromCharCode(0x61 + Math.floor(Math.random() * 26)) +
String.fromCharCode(0x61 + Math.floor(Math.random() * 26))
}

bm('font setter', function () {
ctx.font = `12px ${fontName()}`
ctx.font = `400 6px ${fontName()}`
ctx.font = `1px ${fontName()}`
ctx.font = `normal normal bold 12cm ${fontName()}`
ctx.font = `italic 9mm ${fontName}, "Times New Roman", "Apple Color Emoji", "Comic Sans"`
ctx.font = `small-caps oblique 44px/44px ${fontName()}, "The Quick Brown", "Fox Jumped", "Over", "The", "Lazy Dog"`
})

bm('save/restore', function () {
for (let i = 0; i < 1000; i++) {
const max = i & 15
Expand Down

0 comments on commit f22223c

Please sign in to comment.