Skip to content

testing: revise go help testflags #4508

@gopherbot

Description

@gopherbot

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions