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

go test -bench #24948

Closed
zjb0807 opened this issue Apr 19, 2018 · 2 comments
Closed

go test -bench #24948

zjb0807 opened this issue Apr 19, 2018 · 2 comments

Comments

@zjb0807
Copy link

zjb0807 commented Apr 19, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.10.1

Does this issue reproduce with the latest release?

YES

What operating system and processor architecture are you using (go env)?

[chain33@localhost chain33]$ go env
GOARCH="amd64"
GOBIN="/home/chain33/gopath/bin"
GOCACHE="/home/chain33/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/chain33/gopath"
GORACE=""
GOROOT="/home/chain33/go"
GOTMPDIR=""
GOTOOLDIR="/home/chain33/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build079524249=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"fmt"
	"testing"
)
func Test_1(t *testing.T) {
	fmt.Println("Test_1")
}

func Test_2(t *testing.T) {
	fmt.Println("Test_2")
}

func Benchmark_1(b *testing.B) {
	fmt.Println("Benchmark_1")
}

func Benchmark_2(b *testing.B) {
	fmt.Println("Benchmark_2")
}

to run:

go test -bench=Benchmark_1

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

goos: linux
goarch: amd64
Benchmark_1-4   	Benchmark_1
Benchmark_1
Benchmark_1
Benchmark_1
Benchmark_1
2000000000	         0.00 ns/op
PASS
ok  	_/home/chain33	0.006s

What did you see instead?

[chain33@localhost ~]$ go test -bench=Benchmark_1

Test_1
Test_2
Benchmark_1
goos: linux
goarch: amd64
Benchmark_1-4   	Benchmark_1
Benchmark_1
Benchmark_1
Benchmark_1
Benchmark_1
2000000000	         0.00 ns/op
PASS
ok  	_/home/chain33	0.006s

When I specify benchmarks function name,why does Test_1, Test_2, Benchmark_1 run?

@iand
Copy link
Contributor

iand commented Apr 19, 2018

go test always runs the tests first before any benchmarks. If you want to prevent tests from running you can do something like go test -run=^$ -bench=Benchmark_1

@zjb0807 zjb0807 closed this as completed Apr 19, 2018
@zjb0807
Copy link
Author

zjb0807 commented Apr 19, 2018

thx

@golang golang locked and limited conversation to collaborators Apr 19, 2019
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