1 回答

TA贡献1757条经验 获得超8个赞
它表示用于运行基准测试的CPU数量 - 因此,在您的情况下。6
编辑:
Go 网站上似乎没有正式记录 Benchmark 名称格式,但您可以在标准库源代码中看到名称的制定方式:这里和这里:
runtime.GOMAXPROCS(procs)
benchName := benchmarkName(b.name, procs)
func benchmarkName(name string, n int) string {
if n != 1 {
return fmt.Sprintf("%s-%d", name, n)
}
return name
}
仅供参考:从命令行文档:go help
go help testflag
-cpu 1,2,4
Specify a list of GOMAXPROCS values for which the tests or
benchmarks should be executed. The default is the current value
of GOMAXPROCS.
因此,如果您想强制基准测试使用较少数量的CPU,请使用env var:GOMAXPROCS
$ GOMAXPROCS=2 go test -bench=.
...
BenchmarkStuff-2 1000000000 0.2642 ns/op
或者,您可以对多个 CPU 内核设置进行基准测试,如下所示:
$ go test -bench=. -cpu=1,2,4
...
BenchmarkStuff 1000000000 0.2516 ns/op
BenchmarkStuff-2 1000000000 0.2531 ns/op
BenchmarkStuff-4 1000000000 0.2488 ns/op
- 1 回答
- 0 关注
- 111 浏览
添加回答
举报