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/testing.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/testing.go')
-rw-r--r-- | src/pkg/testing/testing.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/pkg/testing/testing.go b/src/pkg/testing/testing.go index 1fbc4f4a9..654d344c0 100644 --- a/src/pkg/testing/testing.go +++ b/src/pkg/testing/testing.go @@ -9,6 +9,33 @@ // where Xxx can by any alphanumeric string (but the first letter must not be in // [a-z]) and serves to identify the test routine. // These TestXxx routines should be declared within the package they are testing. +// +// Functions of the form +// func BenchmarkXxx(*testing.B) +// are considered benchmarks, and are executed by gotest when the -benchmarks +// flag is provided. +// +// A sample benchmark function looks like this: +// func BenchmarkHello(b *testing.B) { +// for i := 0; i < b.N; i++ { +// fmt.Sprintf("hello") +// } +// } +// The benchmark package will vary b.N until the benchmark function lasts +// long enough to be timed reliably. The output +// testing.BenchmarkHello 500000 4076 ns/op +// means that the loop ran 500000 times at a speed of 4076 ns per loop. +// +// If a benchmark needs some expensive setup before running, the timer +// may be stopped: +// func BenchmarkBigLen(b *testing.B) { +// b.StopTimer(); +// big := NewBig(); +// b.StartTimer(); +// for i := 0; i < b.N; i++ { +// big.Len(); +// } +// } package testing import ( |