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 關注
- 129 瀏覽
添加回答
舉報