Skip to content

Commit 673d12f

Browse files
committed
improve measureText bench, add fillText bench
Using a generic name should give consistent results, at least when comparing to the old Pango implementation. Math.random() seems to bust through FreeType and HarfBuzz caches. The fillText benchmark shows a performance regression vs v3, which I will fix next.
1 parent 1c2da8e commit 673d12f

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎benchmarks/run.js‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ function fontName () {
7171
String.fromCharCode(0x61 + Math.floor(Math.random() * 26))
7272
}
7373

74-
bm('measureText(\'canvas\')', function () {
75-
ctx.font = '12px Arial'
76-
ctx.measureText('canvas')
74+
bm('fillText(Math.random())', function () {
75+
ctx.font = '12px sans-serif'
76+
ctx.fillText(0, 10, String(Math.random()))
77+
})
78+
79+
bm('measureText(Math.random())', function () {
80+
ctx.font = '12px sans-serif'
81+
ctx.measureText(String(Math.random()))
7782
})
7883

7984
bm('font setter', function () {

0 commit comments

Comments
 (0)