go 测试:使用b.Run创建子基准意味着父基准将不会显示来自b.ReportMetric的内容,

thtygnil  于 3个月前  发布在  Go
关注(0)|答案(2)|浏览(40)

Go版本

go版本 go1.21.6 darwin/arm64

在你的模块/工作区中go env的输出:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/Harald/Library/Caches/go-build'
GOENV='/Users/Harald/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/Harald/go/pkg/mod'
GONOPROXY='github.com/dietdoctor/*'
GONOSUMDB='github.com/dietdoctor/*'
GOOS='darwin'
GOPATH='/Users/Harald/go'
GOPRIVATE='github.com/dietdoctor/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.6/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.6/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.6'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/Harald/dd/hive/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/j2/0w9hqz1x01g3j4_yz0w0sw780000gp/T/go-build4150210059=/tmp/go-build -gno-record-gcc-switches -fno-common'

你做了什么?

func BenchmarkTest(b *testing.B) {
	for _, name := range []string{"Test"} {
		b.Run(name, func(b *testing.B) {
			for _, subName := range []string{"Subtest"} {
				b.Run(subName, func(bb *testing.B) {
					bb.ReportMetric(100, "sub_test_metric")
				})
			}
			b.ReportMetric(200, "some_metric")
		})
	}
}

你看到了什么发生?

BenchmarkTest
BenchmarkTest/Test
BenchmarkTest/Test/Subtest
BenchmarkTest/Test/Subtest-8 	1000000000	         0.0000002 ns/op	       100.0 sub_test_metric
PASS

你期望看到什么?

我希望在BenchmarkTest/Test基准测试上报告some_metric

0s7z1bwu

0s7z1bwu2#

@aclements 这个效果是ResetTimer清除extraMap的意外后果,还是有意为之?或许在b.Run具有各种性能影响的情况下,将其视为除了作为子基准测试容器之外的其他任何内容都是无效的?
子基准测试是否应该继承extraMap?

相关问题