-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathshaper_perf_test.go
100 lines (86 loc) · 2.12 KB
/
shaper_perf_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package harfbuzz
import (
"bytes"
"io/ioutil"
"testing"
testdata "github.com/benoitkugler/textlayout-testdata/harfbuzz"
tt "github.com/benoitkugler/textlayout/fonts/truetype"
"github.com/benoitkugler/textlayout/language"
)
// ported from harfbuzz/perf
func BenchmarkShaping(b *testing.B) {
runs := []struct {
name string
textFile string
fontFile string
script language.Script
direction Direction
}{
{
"fa-thelittleprince.txt - Amiri",
"erf_reference/texts/fa-thelittleprince.txt",
"perf_reference/fonts/Amiri-Regular.ttf",
language.Arabic,
RightToLeft,
},
{
"fa-thelittleprince.txt - NotoNastaliqUrdu",
"perf_reference/texts/fa-thelittleprince.txt",
"perf_reference/fonts/NotoNastaliqUrdu-Regular.ttf",
language.Arabic,
RightToLeft,
},
{
"fa-monologue.txt - Amiri",
"perf_reference/texts/fa-monologue.txt",
"perf_reference/fonts/Amiri-Regular.ttf",
language.Arabic,
RightToLeft,
},
{
"fa-monologue.txt - NotoNastaliqUrdu",
"perf_reference/texts/fa-monologue.txt",
"perf_reference/fonts/NotoNastaliqUrdu-Regular.ttf",
language.Arabic,
RightToLeft,
},
{
"en-thelittleprince.txt - Roboto",
"perf_reference/texts/en-thelittleprince.txt",
"perf_reference/fonts/Roboto-Regular.ttf",
language.Latin,
LeftToRight,
},
{
"en-words.txt - Roboto",
"perf_reference/texts/en-words.txt",
"perf_reference/fonts/Roboto-Regular.ttf",
language.Latin,
LeftToRight,
},
}
for _, run := range runs {
b.Run(run.name, func(b *testing.B) {
shapeOne(b, run.textFile, run.fontFile, run.direction, run.script)
})
}
}
func shapeOne(b *testing.B, textFile, fontFile string, direction Direction, script language.Script) {
f, err := testdata.Files.ReadFile(fontFile)
check(err)
fonts, err := tt.Load(bytes.NewReader(f))
check(err)
font := NewFont(fonts[0])
textB, err := ioutil.ReadFile(textFile)
check(err)
text := []rune(string(textB))
buf := NewBuffer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
buf.AddRunes(text, 0, -1)
buf.Props.Direction = direction
buf.Props.Script = script
buf.Shape(font, nil)
buf.Clear()
}
}