diff options
author | Trevor Strohman <trevor.strohman@gmail.com> | 2009-11-19 16:35:34 -0800 |
---|---|---|
committer | Trevor Strohman <trevor.strohman@gmail.com> | 2009-11-19 16:35:34 -0800 |
commit | f79f90ce049e525bc39622aa1d2b4ab17ceb2d49 (patch) | |
tree | b8a0878148ef73d98e08fe7720ff3e654dc4ef14 /src/pkg/testing/regexp_test.go | |
parent | f536e6624783673bbc9b347e43d3144dabf853fe (diff) | |
download | golang-f79f90ce049e525bc39622aa1d2b4ab17ceb2d49.tar.gz |
Adds benchmark support to gotest.
No benchmarks are run unless the --benchmarks=<regexp> flag
is specified on the gotest command line. This change includes
sample benchmarks for regexp.
% gotest --benchmarks=.*
(standard test output redacted)
testing.BenchmarkSimpleMatch 200000 7799 ns/op
testing.BenchmarkUngroupedMatch 20000 76898 ns/op
testing.BenchmarkGroupedMatch 50000 38148 ns/op
R=r, rsc
http://codereview.appspot.com/154173
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/pkg/testing/regexp_test.go')
-rw-r--r-- | src/pkg/testing/regexp_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/pkg/testing/regexp_test.go b/src/pkg/testing/regexp_test.go index 8f6b20c67..66139ea1e 100644 --- a/src/pkg/testing/regexp_test.go +++ b/src/pkg/testing/regexp_test.go @@ -279,3 +279,33 @@ func TestMatchFunction(t *T) { matchFunctionTest(t, test.re, test.text, test.match); } } + +func BenchmarkSimpleMatch(b *B) { + b.StopTimer(); + re, _ := CompileRegexp("a"); + b.StartTimer(); + + for i := 0; i < b.N; i++ { + re.MatchString("a") + } +} + +func BenchmarkUngroupedMatch(b *B) { + b.StopTimer(); + re, _ := CompileRegexp("[a-z]+ [0-9]+ [a-z]+"); + b.StartTimer(); + + for i := 0; i < b.N; i++ { + re.MatchString("word 123 other") + } +} + +func BenchmarkGroupedMatch(b *B) { + b.StopTimer(); + re, _ := CompileRegexp("([a-z]+) ([0-9]+) ([a-z]+)"); + b.StartTimer(); + + for i := 0; i < b.N; i++ { + re.MatchString("word 123 other") + } +} |