diff options
author | Marcel van Lohuizen <mpvl@golang.org> | 2016-05-26 11:46:19 +0200 |
---|---|---|
committer | Marcel van Lohuizen <mpvl@golang.org> | 2016-06-01 10:28:01 +0000 |
commit | ad074e205e4aa4c7762e223df65695d5157b0c4e (patch) | |
tree | 0a571a5a9aba6cc8d49c11e5e7b1335ac9a707e4 | |
parent | 88ae6495d086ed5b0acb94d5adc49434ec47a675 (diff) | |
download | go-ad074e205e4aa4c7762e223df65695d5157b0c4e.tar.gz go-ad074e205e4aa4c7762e223df65695d5157b0c4e.zip |
regexp: use Run for benchmark
Change-Id: I4d19e3221d3789d4c460b421b2d1484253778068
Reviewed-on: https://go-review.googlesource.com/23429
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
-rw-r--r-- | src/regexp/exec_test.go | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/src/regexp/exec_test.go b/src/regexp/exec_test.go index 463fcf1848..69f187e38a 100644 --- a/src/regexp/exec_test.go +++ b/src/regexp/exec_test.go @@ -658,57 +658,42 @@ func makeText(n int) []byte { return text } -func benchmark(b *testing.B, re string, n int) { - r := MustCompile(re) - t := makeText(n) - b.ResetTimer() - b.SetBytes(int64(n)) - for i := 0; i < b.N; i++ { - if r.Match(t) { - b.Fatal("match!") +func BenchmarkMatch(b *testing.B) { + for _, data := range benchData { + r := MustCompile(data.re) + for _, size := range benchSizes { + t := makeText(size.n) + b.Run(data.name+"/"+size.name, func(b *testing.B) { + b.SetBytes(int64(size.n)) + for i := 0; i < b.N; i++ { + if r.Match(t) { + b.Fatal("match!") + } + } + }) } } } -const ( - easy0 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ$" - easy0i = "(?i)ABCDEFGHIJklmnopqrstuvwxyz$" - easy1 = "A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$" - medium = "[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$" - hard = "[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$" - hard1 = "ABCD|CDEF|EFGH|GHIJ|IJKL|KLMN|MNOP|OPQR|QRST|STUV|UVWX|WXYZ" -) +var benchData = []struct{ name, re string }{ + {"Easy0", "ABCDEFGHIJKLMNOPQRSTUVWXYZ$"}, + {"Easy0i", "(?i)ABCDEFGHIJklmnopqrstuvwxyz$"}, + {"Easy1", "A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$"}, + {"Medium", "[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$"}, + {"Hard", "[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$"}, + {"Hard1", "ABCD|CDEF|EFGH|GHIJ|IJKL|KLMN|MNOP|OPQR|QRST|STUV|UVWX|WXYZ"}, +} -func BenchmarkMatchEasy0_32(b *testing.B) { benchmark(b, easy0, 32<<0) } -func BenchmarkMatchEasy0_1K(b *testing.B) { benchmark(b, easy0, 1<<10) } -func BenchmarkMatchEasy0_32K(b *testing.B) { benchmark(b, easy0, 32<<10) } -func BenchmarkMatchEasy0_1M(b *testing.B) { benchmark(b, easy0, 1<<20) } -func BenchmarkMatchEasy0_32M(b *testing.B) { benchmark(b, easy0, 32<<20) } -func BenchmarkMatchEasy0i_32(b *testing.B) { benchmark(b, easy0i, 32<<0) } -func BenchmarkMatchEasy0i_1K(b *testing.B) { benchmark(b, easy0i, 1<<10) } -func BenchmarkMatchEasy0i_32K(b *testing.B) { benchmark(b, easy0i, 32<<10) } -func BenchmarkMatchEasy0i_1M(b *testing.B) { benchmark(b, easy0i, 1<<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) } +var benchSizes = []struct { + name string + n int +}{ + {"32", 32}, + {"1K", 1 << 10}, + {"32K", 32 << 10}, + {"1M", 1 << 20}, + {"32M", 32 << 20}, +} func TestLongest(t *testing.T) { re, err := Compile(`a(|b)`) |