-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmarks_test.go
57 lines (53 loc) · 1.41 KB
/
benchmarks_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
// Benchmarks taken from Go reference library https://github.com/petar-dambovaliev/aho-corasick
package aho_corasick
import "testing"
func BenchmarkReplaceAll(b *testing.B) {
for _, tc := range testCasesReplace {
tt := tc
b.Run(tt.name, func(b *testing.B) {
for _, dfa := range []bool{false, true} {
builder := NewAhoCorasickBuilderBenchmark(Opts{
AsciiCaseInsensitive: true,
MatchOnlyWholeWords: true,
MatchKind: LeftMostLongestMatch,
DFA: dfa,
})
ac := NewReplacerBenchmark(builder.Build(tt.patterns))
dfaStr := "default"
if dfa {
dfaStr = "dfa"
}
b.Run(dfaStr, func(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = ac.ReplaceAll(tt.haystack, tt.replaceWith)
}
})
}
})
}
}
func BenchmarkLeftmostInsensitiveWholeWord(b *testing.B) {
for _, tc := range leftmostInsensitiveWholeWordTestCases {
tt := tc
b.Run(tt.name, func(b *testing.B) {
for _, dfa := range []bool{false, true} {
builder := NewAhoCorasickBuilderBenchmark(Opts{
AsciiCaseInsensitive: true,
MatchOnlyWholeWords: true,
MatchKind: LeftMostLongestMatch,
DFA: dfa,
})
ac := builder.Build(tt.patterns)
dfaStr := "default"
if dfa {
dfaStr = "dfa"
}
b.Run(dfaStr, func(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = ac.FindAll(tt.haystack)
}
})
}
})
}
}