-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmark_test.go
70 lines (66 loc) · 1.28 KB
/
benchmark_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
package gogosseract_test
import (
"bytes"
"context"
"testing"
"github.com/danlock/gogosseract"
"github.com/danlock/pkg/test"
"github.com/google/go-cmp/cmp"
)
func BenchmarkGogosseract(b *testing.B) {
ctx := context.Background()
tess, err := gogosseract.New(ctx, gogosseract.Config{
TrainingData: bytes.NewBuffer(engTrainedData),
})
test.FailOnError(b, err)
defer func() {
test.FailOnError(b, tess.Close(ctx))
}()
tests := []struct {
name string
imgSrc []byte
opts gogosseract.LoadImageOptions
isHOCR bool
wantText string
}{
{
"logo text",
logoImg,
gogosseract.LoadImageOptions{},
false,
logoText,
},
{
"docs text",
docsImg,
gogosseract.LoadImageOptions{},
false,
docsText,
},
{
"underline removal",
underlineImg,
gogosseract.LoadImageOptions{
RemoveUnderlines: true,
},
false,
underlineText,
},
}
for _, tt := range tests {
b.Run(tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
test.FailOnError(b, tess.LoadImage(ctx, bytes.NewBuffer(tt.imgSrc), tt.opts))
var text string
if tt.isHOCR {
text, err = tess.GetHOCR(ctx, nil)
} else {
text, err = tess.GetText(ctx, nil)
}
if text != tt.wantText {
b.Fatalf(cmp.Diff(text, tt.wantText))
}
}
})
}
}