Commit ad074e20 authored by Marcel van Lohuizen's avatar Marcel van Lohuizen

regexp: use Run for benchmark

Change-Id: I4d19e3221d3789d4c460b421b2d1484253778068
Reviewed-on: https://go-review.googlesource.com/23429Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
parent 88ae6495
...@@ -658,57 +658,42 @@ func makeText(n int) []byte { ...@@ -658,57 +658,42 @@ func makeText(n int) []byte {
return text return text
} }
func benchmark(b *testing.B, re string, n int) { func BenchmarkMatch(b *testing.B) {
r := MustCompile(re) for _, data := range benchData {
t := makeText(n) r := MustCompile(data.re)
b.ResetTimer() for _, size := range benchSizes {
b.SetBytes(int64(n)) t := makeText(size.n)
for i := 0; i < b.N; i++ { b.Run(data.name+"/"+size.name, func(b *testing.B) {
if r.Match(t) { b.SetBytes(int64(size.n))
b.Fatal("match!") for i := 0; i < b.N; i++ {
if r.Match(t) {
b.Fatal("match!")
}
}
})
} }
} }
} }
const ( var benchData = []struct{ name, re string }{
easy0 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ$" {"Easy0", "ABCDEFGHIJKLMNOPQRSTUVWXYZ$"},
easy0i = "(?i)ABCDEFGHIJklmnopqrstuvwxyz$" {"Easy0i", "(?i)ABCDEFGHIJklmnopqrstuvwxyz$"},
easy1 = "A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$" {"Easy1", "A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$"},
medium = "[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$" {"Medium", "[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$"},
hard = "[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$" {"Hard", "[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$"},
hard1 = "ABCD|CDEF|EFGH|GHIJ|IJKL|KLMN|MNOP|OPQR|QRST|STUV|UVWX|WXYZ" {"Hard1", "ABCD|CDEF|EFGH|GHIJ|IJKL|KLMN|MNOP|OPQR|QRST|STUV|UVWX|WXYZ"},
) }
func BenchmarkMatchEasy0_32(b *testing.B) { benchmark(b, easy0, 32<<0) } var benchSizes = []struct {
func BenchmarkMatchEasy0_1K(b *testing.B) { benchmark(b, easy0, 1<<10) } name string
func BenchmarkMatchEasy0_32K(b *testing.B) { benchmark(b, easy0, 32<<10) } n int
func BenchmarkMatchEasy0_1M(b *testing.B) { benchmark(b, easy0, 1<<20) } }{
func BenchmarkMatchEasy0_32M(b *testing.B) { benchmark(b, easy0, 32<<20) } {"32", 32},
func BenchmarkMatchEasy0i_32(b *testing.B) { benchmark(b, easy0i, 32<<0) } {"1K", 1 << 10},
func BenchmarkMatchEasy0i_1K(b *testing.B) { benchmark(b, easy0i, 1<<10) } {"32K", 32 << 10},
func BenchmarkMatchEasy0i_32K(b *testing.B) { benchmark(b, easy0i, 32<<10) } {"1M", 1 << 20},
func BenchmarkMatchEasy0i_1M(b *testing.B) { benchmark(b, easy0i, 1<<20) } {"32M", 32 << 20},
func BenchmarkMatchEasy0i_32M(b *testing.B) { benchmark(b, easy0i, 32<<20) } }
func BenchmarkMatchEasy1_32(b *testing.B) { benchmark(b, easy1, 32<<0) }
func BenchmarkMatchEasy1_1K(b *testing.B) { benchmark(b, easy1, 1<<10) }
func BenchmarkMatchEasy1_32K(b *testing.B) { benchmark(b, easy1, 32<<10) }
func BenchmarkMatchEasy1_1M(b *testing.B) { benchmark(b, easy1, 1<<20) }
func BenchmarkMatchEasy1_32M(b *testing.B) { benchmark(b, easy1, 32<<20) }
func BenchmarkMatchMedium_32(b *testing.B) { benchmark(b, medium, 32<<0) }
func BenchmarkMatchMedium_1K(b *testing.B) { benchmark(b, medium, 1<<10) }
func BenchmarkMatchMedium_32K(b *testing.B) { benchmark(b, medium, 32<<10) }
func BenchmarkMatchMedium_1M(b *testing.B) { benchmark(b, medium, 1<<20) }
func BenchmarkMatchMedium_32M(b *testing.B) { benchmark(b, medium, 32<<20) }
func BenchmarkMatchHard_32(b *testing.B) { benchmark(b, hard, 32<<0) }
func BenchmarkMatchHard_1K(b *testing.B) { benchmark(b, hard, 1<<10) }
func BenchmarkMatchHard_32K(b *testing.B) { benchmark(b, hard, 32<<10) }
func BenchmarkMatchHard_1M(b *testing.B) { benchmark(b, hard, 1<<20) }
func BenchmarkMatchHard_32M(b *testing.B) { benchmark(b, hard, 32<<20) }
func BenchmarkMatchHard1_32(b *testing.B) { benchmark(b, hard1, 32<<0) }
func BenchmarkMatchHard1_1K(b *testing.B) { benchmark(b, hard1, 1<<10) }
func BenchmarkMatchHard1_32K(b *testing.B) { benchmark(b, hard1, 32<<10) }
func BenchmarkMatchHard1_1M(b *testing.B) { benchmark(b, hard1, 1<<20) }
func BenchmarkMatchHard1_32M(b *testing.B) { benchmark(b, hard1, 32<<20) }
func TestLongest(t *testing.T) { func TestLongest(t *testing.T) {
re, err := Compile(`a(|b)`) re, err := Compile(`a(|b)`)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment