diff options
author | Rob Pike <r@golang.org> | 2009-11-19 23:12:01 -0800 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-11-19 23:12:01 -0800 |
commit | 7e51eb4a6b371c20486adfa507cfd164ef0c5c0c (patch) | |
tree | f36ce42b4b36a76bb2cf8a7bbd2d6ca9bbad9e27 /src/pkg/regexp/all_test.go | |
parent | 35fad56a1ec09f32c18c3315479ddb277bb112a9 (diff) | |
download | golang-7e51eb4a6b371c20486adfa507cfd164ef0c5c0c.tar.gz |
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
Diffstat (limited to 'src/pkg/regexp/all_test.go')
-rw-r--r-- | src/pkg/regexp/all_test.go | 27 |
1 files changed, 27 insertions, 0 deletions
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; + } + } +} |