-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinsert_test.go
137 lines (124 loc) · 3.08 KB
/
insert_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package frame
import (
"image"
"strings"
"testing"
. "github.com/as/font"
)
func TestInsertOneChar(t *testing.T) {
h, _, have, _ := abtestbg(R)
h.Insert([]byte("1"), 0)
h.Untick()
//etch.WriteFile(t, `testdata/TestInsertOneChar.expected.png`, have)
check(t, have, "TestInsertOneChar", testMode)
}
func TestInsert10Chars(t *testing.T) {
h, _, have, _ := abtestbg(R)
for i := 0; i < 10; i++ {
h.Insert([]byte("1"), 0)
}
check(t, have, "TestInsert10Chars", testMode)
}
func TestInsert22Chars2Lines(t *testing.T) {
h, _, have, _ := abtestbg(R)
for j := 0; j < 2; j++ {
for i := 0; i < 10; i++ {
h.Insert([]byte("1"), h.Len())
}
h.Insert([]byte("\n"), h.Len())
}
check(t, have, "TestInsert22Chars2Lines", testMode)
}
func TestInsert1000(t *testing.T) {
h, _, have, _ := abtestbg(R)
for j := 0; j < 1000; j++ {
h.Insert([]byte{byte(j)}, int64(j))
}
check(t, have, "TestInsert1000", testMode)
}
func TestInsertTabSpaceNewline(t *testing.T) {
h, _, have, _ := abtestbg(R)
for j := 0; j < 5; j++ {
h.Insert([]byte("abc\t \n\n\t $\n"), int64(j))
}
check(t, have, "TestInsertTabSpaceNewline", testMode)
}
type benchOp struct {
name string
data string
at int64
}
var dst = image.NewRGBA(image.Rect(0, 0, 1024, 768))
func BenchmarkInsertGoMono(b *testing.B) { b.Helper(); bInsert(b, withFace(NewGoMono(fsize))) }
func BenchmarkInsertGoMonoCache(b *testing.B) {
if b, ok := interface{}(b).(help); ok {
b.Helper()
}
bInsert(b, withFace(NewCache(NewGoMono(fsize))))
}
func BenchmarkInsertGoMonoReplaceCache(b *testing.B) {
if b, ok := interface{}(b).(help); ok {
b.Helper()
}
bInsert(b, withFace(
NewCache(
Replacer(
NewGoMono(fsize), NewHex(fsize), nil,
),
),
),
)
}
func BenchmarkInsertGoMonoCliche(b *testing.B) {
if b, ok := interface{}(b).(help); ok {
b.Helper()
}
bInsert(b, withFace(NewCliche(NewGoMono(fsize))))
}
func BenchmarkInsertGoMonoRune(b *testing.B) {
if b, ok := interface{}(b).(help); ok {
b.Helper()
}
bInsert(b, withFace(NewRune(NewGoMono(fsize))))
}
func BenchmarkInsertGoMonoRuneCache(b *testing.B) {
if b, ok := interface{}(b).(help); ok {
b.Helper()
}
bInsert(b, withFace(NewCache(NewRune(NewGoMono(fsize)))))
}
func withFace(ft Face) *Frame {
return New(dst, dst.Bounds(), &Config{Face: ft, Color: A})
}
func bInsert(b *testing.B, f *Frame) {
// b.Skip("not ready")
if b, ok := interface{}(b).(help); ok {
b.Helper()
}
for _, v := range []benchOp{
{"1", "a", 0},
{"10", strings.Repeat("a\n", 10), 0},
{"100", strings.Repeat("a\n", 100), 0},
{"1000", strings.Repeat("a\n", 1000), 0},
{"10000", strings.Repeat("a\n", 10000), 0},
{"100000", strings.Repeat("a\n", 100000), 0},
} {
b.Run(v.name, func(b *testing.B) {
bb := []byte(v.data)
b.SetBytes(int64(len(bb)))
at := v.at
b.ResetTimer()
for i := 0; i < b.N; i++ {
f.Insert(bb, at)
}
})
}
}
// help is an interface that allows this code to use Go1.9's t.Helper() method
// without breaking out of data continuous integration components (CircleCI) which
// run older Go versions not supporting t.Helper().
//
//
type help interface {
Helper()
}