From 7e51eb4a6b371c20486adfa507cfd164ef0c5c0c Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 19 Nov 2009 23:12:01 -0800 Subject: add a match arena to regexp to avoid generating garbage. simple regexps run 20x faster. the regex-dna benchmark goes 3x faster. R=rsc CC=golang-dev http://codereview.appspot.com/156108 --- src/pkg/regexp/all_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/pkg/regexp/all_test.go') diff --git a/src/pkg/regexp/all_test.go b/src/pkg/regexp/all_test.go index 522324871..fb6f3a030 100644 --- a/src/pkg/regexp/all_test.go +++ b/src/pkg/regexp/all_test.go @@ -60,6 +60,7 @@ type tester struct { } var matches = []tester{ + tester{`^abcdefg`, "abcdefg", vec{0, 7}}, tester{`a+`, "baaab", vec{1, 4}}, tester{"abcd..", "abcdef", vec{0, 6}}, tester{``, "", vec{0, 0}}, @@ -450,3 +451,29 @@ func TestAllMatches(t *testing.T) { } } } + +func BenchmarkLiteral(b *testing.B) { + x := strings.Repeat("x", 50); + b.StopTimer(); + re, _ := Compile(x); + b.StartTimer(); + for i := 0; i < b.N; i++ { + if !re.MatchString(x) { + println("no match!"); + break; + } + } +} + +func BenchmarkNotLiteral(b *testing.B) { + x := strings.Repeat("x", 49); + b.StopTimer(); + re, _ := Compile("^" + x); + b.StartTimer(); + for i := 0; i < b.N; i++ { + if !re.MatchString(x) { + println("no match!"); + break; + } + } +} -- cgit v1.2.3