-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
61 lines (53 loc) · 1.19 KB
/
Copy pathbenchmark_test.go
File metadata and controls
61 lines (53 loc) · 1.19 KB
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
package main
import (
"bytes"
"strings"
"testing"
)
func benchmarkData() []byte {
line := "INFO alpha beta gamma delta ERROR target_token omega sigma tau\n"
return bytes.Repeat([]byte(line), 4096)
}
func BenchmarkDoGrepFixedUTF8(b *testing.B) {
data := benchmarkData()
arg := &GrepArg{
pattern: "target_token",
needle: []byte("target_token"),
ascii: true,
}
ignorebinary = false
ignorecase = false
only = false
list = false
invert = false
count = false
number = false
b.ReportAllocs()
b.SetBytes(int64(len(data)))
for i := 0; i < b.N; i++ {
arg.buf.Reset()
doGrepFixedUTF8("bench.txt", data, arg, arg.needle)
}
}
func BenchmarkDoGrepFixedUTF8IgnoreCaseASCII(b *testing.B) {
data := []byte(strings.ReplaceAll(string(benchmarkData()), "target_token", "TaRgEt_ToKeN"))
arg := &GrepArg{
pattern: "target_token",
needle: []byte("target_token"),
folded: []byte("target_token"),
ascii: true,
}
ignorebinary = false
ignorecase = true
only = false
list = false
invert = false
count = false
number = false
b.ReportAllocs()
b.SetBytes(int64(len(data)))
for i := 0; i < b.N; i++ {
arg.buf.Reset()
doGrepFixedUTF8FoldASCII("bench.txt", data, arg, arg.folded)
}
}