Skip to content

Commit a53ae0f

Browse files
committed
add font setter benchmarks
1 parent 1d956b7 commit a53ae0f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

benchmarks/run.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ function done (benchmark, times, start, isAsync) {
6464

6565
// node-canvas
6666

67+
function fontName () {
68+
return String.fromCharCode(0x61 + Math.floor(Math.random() * 26)) +
69+
String.fromCharCode(0x61 + Math.floor(Math.random() * 26)) +
70+
String.fromCharCode(0x61 + Math.floor(Math.random() * 26)) +
71+
String.fromCharCode(0x61 + Math.floor(Math.random() * 26))
72+
}
73+
74+
bm('font setter', function () {
75+
ctx.font = `12px ${fontName()}`
76+
ctx.font = `400 6px ${fontName()}`
77+
ctx.font = `1px ${fontName()}`
78+
ctx.font = `normal normal bold 12cm ${fontName()}`
79+
ctx.font = `italic 9mm ${fontName}, "Times New Roman", "Apple Color Emoji", "Comic Sans"`
80+
ctx.font = `small-caps oblique 44px/44px ${fontName()}, "The Quick Brown", "Fox Jumped", "Over", "The", "Lazy Dog"`
81+
})
82+
6783
bm('save/restore', function () {
6884
for (let i = 0; i < 1000; i++) {
6985
const max = i & 15

0 commit comments

Comments
 (0)