@@ -14,9 +14,9 @@ import (
14
14
15
15
akahocorasick "github.com/anknown/ahocorasick"
16
16
cfahocorasick "github.com/cloudflare/ahocorasick"
17
+ forkahocorasick "github.com/pedroegsilva/ahocorasick/ahocorasick"
17
18
"github.com/pedroegsilva/gofindthem/dsl"
18
19
"github.com/pedroegsilva/gofindthem/finder"
19
- pdahocorasick "github.com/petar-dambovaliev/aho-corasick"
20
20
)
21
21
22
22
func init () {
@@ -113,8 +113,8 @@ func BenchmarkAhocorasickAnknownBuild100(b *testing.B) {
113
113
BMAnknownBuild (exp100 , b )
114
114
}
115
115
116
- func BenchmarkAhocorasickPetarDambovalievBuild100 (b * testing.B ) {
117
- BMPetarDambovalievBuild (exp100 , b )
116
+ func BenchmarkAhocorasickCloudflareForkBuild100 (b * testing.B ) {
117
+ BMCloudflareForkBuild (exp100 , b )
118
118
}
119
119
120
120
func BenchmarkAhocorasickCloudFlareSearch100 (b * testing.B ) {
@@ -133,12 +133,12 @@ func BenchmarkDslWithAnknown100(b *testing.B) {
133
133
BMDslSearch ([]string {exp100 }, & finder.AnknownEngine {}, b )
134
134
}
135
135
136
- func BenchmarkAhocorasickPetarDambovalievSearch100 (b * testing.B ) {
137
- BMPetarDambovalievSearch ([]string {exp100 }, b )
136
+ func BenchmarkAhocorasickCloudflareForkSearch100 (b * testing.B ) {
137
+ BMCloudflareForkSearch ([]string {exp100 }, b )
138
138
}
139
139
140
- func BenchmarkDslWithPetarDambovaliev100 (b * testing.B ) {
141
- BMDslSearch ([]string {exp100 }, & finder.PetarDambovalievEngine {}, b )
140
+ func BenchmarkDslWithCloudflareFork100 (b * testing.B ) {
141
+ BMDslSearch ([]string {exp100 }, & finder.CloudflareForkEngine {}, b )
142
142
}
143
143
144
144
// 10000 terms
@@ -171,8 +171,8 @@ func BenchmarkAhocorasickAnknownBuild10000(b *testing.B) {
171
171
BMAnknownBuild (exp10000 , b )
172
172
}
173
173
174
- func BenchmarkAhocorasickPetarDambovalievBuild10000 (b * testing.B ) {
175
- BMPetarDambovalievBuild (exp10000 , b )
174
+ func BenchmarkAhocorasickCloudflareForkBuild10000 (b * testing.B ) {
175
+ BMCloudflareForkBuild (exp10000 , b )
176
176
}
177
177
178
178
func BenchmarkAhocorasickCloudFlareSearch10000 (b * testing.B ) {
@@ -191,12 +191,12 @@ func BenchmarkDslWithAnknown10000(b *testing.B) {
191
191
BMDslSearch ([]string {exp10000 }, & finder.AnknownEngine {}, b )
192
192
}
193
193
194
- func BenchmarkAhocorasickPetarDambovalievSearch10000 (b * testing.B ) {
195
- BMPetarDambovalievSearch ([]string {exp10000 }, b )
194
+ func BenchmarkAhocorasickCloudflareForkSearch10000 (b * testing.B ) {
195
+ BMCloudflareForkSearch ([]string {exp10000 }, b )
196
196
}
197
197
198
- func BenchmarkDslWithPetarDambovaliev10000 (b * testing.B ) {
199
- BMDslSearch ([]string {exp10000 }, & finder.PetarDambovalievEngine {}, b )
198
+ func BenchmarkDslWithCloudflareFork10000 (b * testing.B ) {
199
+ BMDslSearch ([]string {exp10000 }, & finder.CloudflareForkEngine {}, b )
200
200
}
201
201
202
202
// dsl specific
@@ -220,12 +220,12 @@ func BenchmarkDslWithAnknown10Exps(b *testing.B) {
220
220
BMDslSearch (exps10 , & finder.AnknownEngine {}, b )
221
221
}
222
222
223
- func BenchmarkOnlyPetarDambovaliev10Exps (b * testing.B ) {
224
- BMPetarDambovalievSearch (exps10 , b )
223
+ func BenchmarkOnlyCloudflareFork10Exps (b * testing.B ) {
224
+ BMCloudflareForkSearch (exps10 , b )
225
225
}
226
226
227
- func BenchmarkDslWithPetarDambovaliev10Exps (b * testing.B ) {
228
- BMDslSearch (exps10 , & finder.PetarDambovalievEngine {}, b )
227
+ func BenchmarkDslWithCloudflareFork10Exps (b * testing.B ) {
228
+ BMDslSearch (exps10 , & finder.CloudflareForkEngine {}, b )
229
229
}
230
230
231
231
func BenchmarkDslWithEmptyEngine100Exps (b * testing.B ) {
@@ -248,12 +248,12 @@ func BenchmarkDslWithAnknown100Exps(b *testing.B) {
248
248
BMDslSearch (exps100 , & finder.AnknownEngine {}, b )
249
249
}
250
250
251
- func BenchmarkOnlyPetarDambovaliev100Exps (b * testing.B ) {
252
- BMPetarDambovalievSearch (exps100 , b )
251
+ func BenchmarkOnlyCloudflareFork100Exps (b * testing.B ) {
252
+ BMCloudflareForkSearch (exps100 , b )
253
253
}
254
254
255
- func BenchmarkDslWithPetarDambovaliev100Exps (b * testing.B ) {
256
- BMDslSearch (exps100 , & finder.PetarDambovalievEngine {}, b )
255
+ func BenchmarkDslWithCloudflareFork100Exps (b * testing.B ) {
256
+ BMDslSearch (exps100 , & finder.CloudflareForkEngine {}, b )
257
257
}
258
258
259
259
func BenchmarkDslWithEmptyEngine1000Exps (b * testing.B ) {
@@ -276,33 +276,33 @@ func BenchmarkDslWithAnknown1000Exps(b *testing.B) {
276
276
BMDslSearch (exps1000 , & finder.AnknownEngine {}, b )
277
277
}
278
278
279
- func BenchmarkOnlyPetarDambovaliev1000Exps (b * testing.B ) {
280
- BMPetarDambovalievSearch (exps1000 , b )
279
+ func BenchmarkOnlyCloudflareFork1000Exps (b * testing.B ) {
280
+ BMCloudflareForkSearch (exps1000 , b )
281
281
}
282
282
283
- func BenchmarkDslWithPetarDambovaliev1000Exps (b * testing.B ) {
284
- BMDslSearch (exps1000 , & finder.PetarDambovalievEngine {}, b )
283
+ func BenchmarkDslWithCloudflareFork1000Exps (b * testing.B ) {
284
+ BMDslSearch (exps1000 , & finder.CloudflareForkEngine {}, b )
285
285
}
286
286
287
287
func BenchmarkUseCasesDsl (b * testing.B ) {
288
288
expressions := []string {
289
289
`"foo" and "bar"` ,
290
290
}
291
- BMDslSearch (expressions , & finder.PetarDambovalievEngine {}, b )
291
+ BMDslSearch (expressions , & finder.CloudflareForkEngine {}, b )
292
292
}
293
293
294
294
func BenchmarkUseCasesDslWithRegex (b * testing.B ) {
295
295
expressions := []string {
296
296
`r"foo.*bar" and r"bar.*foo"` ,
297
297
}
298
- BMDslSearch (expressions , & finder.PetarDambovalievEngine {}, b )
298
+ BMDslSearch (expressions , & finder.CloudflareForkEngine {}, b )
299
299
}
300
300
301
301
func BenchmarkUseCasesDslWithInord (b * testing.B ) {
302
302
expressions := []string {
303
303
`INORD("foo" and "bar") and INORD("bar" and "foo")` ,
304
304
}
305
- BMDslSearch (expressions , & finder.PetarDambovalievEngine {}, b )
305
+ BMDslSearch (expressions , & finder.CloudflareForkEngine {}, b )
306
306
}
307
307
308
308
func BenchmarkUseCasesRegexOnly (b * testing.B ) {
@@ -367,23 +367,16 @@ func BMAnknownBuild(exp string, b *testing.B) {
367
367
}
368
368
}
369
369
370
- func BMPetarDambovalievBuild (exp string , b * testing.B ) {
371
- p := dsl .NewParser (strings .NewReader (exp100 ), true )
370
+ func BMCloudflareForkBuild (exp string , b * testing.B ) {
371
+ p := dsl .NewParser (strings .NewReader (exp ), true )
372
372
p .Parse ()
373
- dict := []string {}
374
-
373
+ dict := [][]byte {}
375
374
for key := range p .GetKeywords () {
376
- dict = append (dict , key )
375
+ dict = append (dict , [] byte ( key ) )
377
376
}
378
377
379
378
for i := 0 ; i < b .N ; i ++ {
380
- builder := pdahocorasick .NewAhoCorasickBuilder (pdahocorasick.Opts {
381
- AsciiCaseInsensitive : true ,
382
- MatchOnlyWholeWords : false ,
383
- MatchKind : pdahocorasick .LeftMostLongestMatch ,
384
- DFA : true ,
385
- })
386
- builder .Build (dict )
379
+ forkahocorasick .NewMatcher (dict )
387
380
}
388
381
}
389
382
@@ -426,27 +419,22 @@ func BMAnknownSearch(exps []string, b *testing.B) {
426
419
}
427
420
}
428
421
429
- func BMPetarDambovalievSearch (exps []string , b * testing.B ) {
422
+ func BMCloudflareForkSearch (exps []string , b * testing.B ) {
430
423
findthem := finder .NewFinder (& finder.EmptyEngine {}, & finder.RegexpEngine {}, true )
431
424
for _ , exp := range exps {
432
425
findthem .AddExpression (exp )
433
426
}
434
427
435
- dict := []string {}
436
-
428
+ dict := [][]byte {}
437
429
for key := range findthem .GetKeywords () {
438
- dict = append (dict , key )
430
+ dict = append (dict , [] byte ( key ) )
439
431
}
440
432
441
- builder := pdahocorasick .NewAhoCorasickBuilder (pdahocorasick.Opts {
442
- AsciiCaseInsensitive : true ,
443
- MatchOnlyWholeWords : false ,
444
- MatchKind : pdahocorasick .LeftMostLongestMatch ,
445
- DFA : true ,
446
- })
447
- bld := builder .Build (dict )
433
+ m := forkahocorasick .NewMatcher (dict )
434
+
435
+ content := []byte (randText100000 )
448
436
for i := 0 ; i < b .N ; i ++ {
449
- bld . FindAll ( randText100000 )
437
+ m . MatchAll ( content )
450
438
}
451
439
}
452
440
0 commit comments