Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: revise go help testflags #4508

Closed
gopherbot opened this issue Dec 9, 2012 · 4 comments
Closed

testing: revise go help testflags #4508

gopherbot opened this issue Dec 9, 2012 · 4 comments
Milestone

Comments

@gopherbot
Copy link

by bronze1man:

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.
@cznic
Copy link
Contributor

cznic commented Dec 9, 2012

Comment 1:

#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".

@rsc
Copy link
Contributor

rsc commented Dec 9, 2012

Comment 2:

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

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@gopherbot
Copy link
Author

Comment 3 by bronze1man:

Great. One example may help.

@rsc
Copy link
Contributor

rsc commented Feb 4, 2013

Comment 4:

This issue was closed by revision 89a2a8c.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants