@@ -2,6 +2,7 @@ package tests
22
33import (
44 "os"
5+ "regexp"
56 "strings"
67 "testing"
78
@@ -60,7 +61,7 @@ func BenchmarkBlockScan(b *testing.B) {
6061 isRaceBuilder := strings .HasSuffix (testenv (), "-race" )
6162
6263 for _ , data := range benchData {
63- p := hyperscan .NewPattern (data .re )
64+ p := hyperscan .NewPattern (data .re , hyperscan . MultiLine )
6465 db , err := hyperscan .NewBlockDatabase (p )
6566 if err != nil {
6667 b .Fatalf ("compile pattern %s: `%s`, %s" , data .name , data .re , err )
@@ -72,7 +73,7 @@ func BenchmarkBlockScan(b *testing.B) {
7273 }
7374
7475 m := func (id uint , from , to uint64 , flags uint , context interface {}) error {
75- return nil
76+ return hyperscan . ErrUnexpected
7677 }
7778
7879 for _ , size := range benchSizes {
@@ -81,7 +82,7 @@ func BenchmarkBlockScan(b *testing.B) {
8182 }
8283 t := makeText (size .n )
8384 b .Run (data .name + "/" + size .name , func (b * testing.B ) {
84- b .SetBytes (int64 (size . n ))
85+ b .SetBytes (int64 (len ( t ) ))
8586 for i := 0 ; i < b .N ; i ++ {
8687 if err = db .Scan (t , s , m , nil ); err != nil {
8788 b .Fatalf ("match, %s" , err )
@@ -91,3 +92,25 @@ func BenchmarkBlockScan(b *testing.B) {
9192 }
9293 }
9394}
95+
96+ func BenchmarkMatch (b * testing.B ) {
97+ isRaceBuilder := strings .HasSuffix (testenv (), "-race" )
98+
99+ for _ , data := range benchData {
100+ r := regexp .MustCompile (data .re )
101+ for _ , size := range benchSizes {
102+ if (isRaceBuilder || testing .Short ()) && size .n > 1 << 10 {
103+ continue
104+ }
105+ t := makeText (size .n )
106+ b .Run (data .name + "/" + size .name , func (b * testing.B ) {
107+ b .SetBytes (int64 (size .n ))
108+ for i := 0 ; i < b .N ; i ++ {
109+ if r .Match (t ) {
110+ b .Fatal ("match!" )
111+ }
112+ }
113+ })
114+ }
115+ }
116+ }
0 commit comments