You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:
Run "go version" and compare against
http://golang.org/doc/devel/release.html If a newer version of Go exists,
install it and retry what you did to reproduce the problem.
Thanks.
What steps will reproduce the problem?
As a newer ,I want use Benchmark from go test to benchmark my function.
here is my test file:
package main
import "testing"
func BenchmarkLoop(b *testing.B){
for i:=0;i<b.N;i++ {
}
}
But I look around the doc, I still do not know how to run Benchmark.
1.testing package says:
Functions of the form
func BenchmarkXxx(*testing.B)
are considered benchmarks, and are executed by the "go test" command when the
-test.bench flag is provided.
2.go test command says:
The test binary also accepts flags that control execution of the test; these flags are
also accessible by 'go test'. See 'go help testflag' for details.
3.go help testflag says:
-test.bench pattern
Run benchmarks matching the regular expression.
By default, no benchmarks run.
then I tried:
1.rename my test file to benchmark_test.go
2.put benchmark_test.go in a standalone directory.
3.go test -test.bench ./
do not work.
4.I tried again:(Do I forget regular expression?)
go test -test.bench * ./
do not work.
5.I tried again:(regular expression!!!!)
go test -test.bench . ./
It works!
What is the expected output?
An example in documents to tell me how to do benchmark.
What do you see instead?
I guess three times.
Which compiler are you using (5g, 6g, 8g, gccgo)?
6g
Which operating system are you using?
ubuntu 1204 server 64bit
Which version are you using? (run 'go version')
go version go1.0.3
Please provide any additional information below.
The text was updated successfully, but these errors were encountered:
#3: Provides correct information. Pattern `./` doesn't match `BenchmarkLoop`.
#4: You're not providing a (benchmark's name) pattern, instead (unescaped/naked) `*` is
expanded by the shell to a list of all file names in cwd. I.e. the first one listed was
used as a (non matching) pattern.
#5: Now the regexp is correct (`.` matches BenchmarkLoop). Alternative examples which
should work: `go test -bench B`, `go test -bench Loop`. No need for the `./` if the
*_test.go files are in cwd.
Suggesting to close w/ "Working as inteded".
I think we can add something like
By default no benchmarks run.
To run all benchmarks, use a pattern that will match them all, like:
-benchmark .
I'd also like to swap the flag descriptions. It should list the flags and then
at the end mention that binaries need -test. Most people shouldn't need
to say '-test.'.
to the 'go help testflag' output
by bronze1man:
The text was updated successfully, but these errors were encountered: