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/cmd | |
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/cmd')
-rw-r--r-- | src/cmd/gotest/doc.go | 13 | ||||
-rwxr-xr-x | src/cmd/gotest/gotest | 14 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/cmd/gotest/doc.go b/src/cmd/gotest/doc.go index e1a87c43c..40c40fc1f 100644 --- a/src/cmd/gotest/doc.go +++ b/src/cmd/gotest/doc.go @@ -19,6 +19,12 @@ They should have signature func TestXXX(t *testing.T) { ... } +Benchmark functions can be written as well; they will be run only +when the -benchmarks flag is provided. Benchmarks should have +signature + + func BenchmarkXXX(b *testing.B) { ... } + See the documentation of the testing package for more information. By default, gotest needs no arguments. It compiles all the .go files @@ -36,14 +42,15 @@ The resulting binary, called (for amd64) 6.out, has a couple of arguments. Usage: - 6.out [-v] [-match pattern] + 6.out [-v] [-match pattern] [-benchmarks pattern] -The -v flag causes the tests to be logged as they run. The --match +The -v flag causes the tests to be logged as they run. The -match flag causes only those tests whose names match the regular expression pattern to be run. By default all tests are run silently. If all the specified test pass, 6.out prints PASS and exits with a 0 exit code. If any tests fail, it prints FAIL and exits with a non-zero -code. +code. The -benchmarks flag is analogous to the -match flag, but +applies to benchmarks. No benchmarks run by default. */ package documentation diff --git a/src/cmd/gotest/gotest b/src/cmd/gotest/gotest index 584578e91..5f87b4791 100755 --- a/src/cmd/gotest/gotest +++ b/src/cmd/gotest/gotest @@ -118,6 +118,9 @@ importpath=$(gomake -s importpath) echo 'gotest: error: no tests matching '$pattern in _test/$importpath.a $xofile 1>&2 exit 2 fi + # benchmarks are named BenchmarkFoo. + pattern='Benchmark([^a-z].*)?' + benchmarks=$(6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' | grep -v '·.*[.·]' | sed 's/.* //; s/·/./') # package spec echo 'package main' @@ -140,10 +143,19 @@ importpath=$(gomake -s importpath) echo ' testing.Test{ "'$i'", '$i' },' done echo '}' + # benchmark array + echo 'var benchmarks = []testing.Benchmark {' + for i in $benchmarks + do + echo ' testing.Benchmark{ "'$i'", '$i' },' + done + echo '}' + # body echo echo 'func main() {' - echo ' testing.Main(tests)' + echo ' testing.Main(tests);' + echo ' testing.RunBenchmarks(benchmarks)' echo '}' }>_testmain.go |