From: Russ Cox Date: Tue, 2 Oct 2018 13:09:10 +0000 (-0400) Subject: regexp: fix BenchmarkMatch_onepass_regex X-Git-Tag: go1.12beta1~810 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=872a5479574f11d7ebe78118226f2a423e89c993;p=gostls13.git regexp: fix BenchmarkMatch_onepass_regex This benchmark - in contrast to all other benchmarks - was running the regexp match on 1-byte substrings of the input instead of the entire input. Worse, it was doing so by preallocating a slice of slices of every 1-byte substring. Needless to say, this does not accurately reflect what happens when the regexp matcher is given a large input. Change-Id: Icd5b95f0e43f554a6b93164916745941366e03d6 Reviewed-on: https://go-review.googlesource.com/c/139778 Run-TryBot: Russ Cox Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/regexp/exec_test.go b/src/regexp/exec_test.go index 5f8e747b17..02258e6e74 100644 --- a/src/regexp/exec_test.go +++ b/src/regexp/exec_test.go @@ -692,18 +692,12 @@ func BenchmarkMatch_onepass_regex(b *testing.B) { continue } t := makeText(size.n) - bs := make([][]byte, len(t)) - for i, s := range t { - bs[i] = []byte{s} - } b.Run(size.name, func(b *testing.B) { b.SetBytes(int64(size.n)) b.ReportAllocs() for i := 0; i < b.N; i++ { - for _, byts := range bs { - if !r.Match(byts) { - b.Fatal("not match!") - } + if !r.Match(t) { + b.Fatal("not match!") } } })