1
// Copyright 2013 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
13
// benchmark based on regexp/exec_test.go
17
func makeRegexpText(n int) []byte {
18
rand.Seed(0) // For reproducibility.
19
if len(regexpText) >= n {
22
regexpText = make([]byte, n)
23
for i := range regexpText {
24
if rand.Intn(30) == 0 {
27
regexpText[i] = byte(rand.Intn(0x7E+1-0x20) + 0x20)
33
func benchmark(b *testing.B, re string, n int) {
34
r := regexp.MustCompile(re)
35
t := makeRegexpText(n)
38
for i := 0; i < b.N; i++ {
46
easy0 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ$"
47
easy1 = "A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$"
48
medium = "[XYZ]ABCDEFGHIJKLMNOPQRSTUVWXYZ$"
49
hard = "[ -~]*ABCDEFGHIJKLMNOPQRSTUVWXYZ$"
52
func BenchmarkRegexpMatchEasy0_32(b *testing.B) { benchmark(b, easy0, 32<<0) }
53
func BenchmarkRegexpMatchEasy0_1K(b *testing.B) { benchmark(b, easy0, 1<<10) }
54
func BenchmarkRegexpMatchEasy1_32(b *testing.B) { benchmark(b, easy1, 32<<0) }
55
func BenchmarkRegexpMatchEasy1_1K(b *testing.B) { benchmark(b, easy1, 1<<10) }
56
func BenchmarkRegexpMatchMedium_32(b *testing.B) { benchmark(b, medium, 1<<0) }
57
func BenchmarkRegexpMatchMedium_1K(b *testing.B) { benchmark(b, medium, 1<<10) }
58
func BenchmarkRegexpMatchHard_32(b *testing.B) { benchmark(b, hard, 32<<0) }
59
func BenchmarkRegexpMatchHard_1K(b *testing.B) { benchmark(b, hard, 1<<10) }