英文:
Go Benchmark how does it work
问题
以下是翻译好的内容:
我已经让我的Go基准测试与我的API调用一起工作了,但是我不太确定下面的输出是什么意思:
$ go test intapi -bench=. -benchmem -cover -v -cpuprofile=cpu.out
=== RUN TestAuthenticate
--- PASS: TestAuthenticate (0.00 seconds)
PASS
BenchmarkAuthenticate 20000 105010 ns/op 3199 B/op 49 allocs/op
coverage: 0.0% of statements
ok intapi 4.349s
它是如何知道要进行多少次调用的?我确实有一个循环,循环的大小是b.N
,但是Golang是如何知道要运行多少次的?
另外,我现在有了CPU分析文件。我该如何使用它来查看呢?
英文:
I've got my Go benchmark working with my API calls but I'm not exactly sure what it means below:
$ go test intapi -bench=. -benchmem -cover -v -cpuprofile=cpu.out
=== RUN TestAuthenticate
--- PASS: TestAuthenticate (0.00 seconds)
PASS
BenchmarkAuthenticate 20000 105010 ns/op 3199 B/op 49 allocs/op
coverage: 0.0% of statements
ok intapi 4.349s
How does it know how many calls it should make? I do have a loop with b.N
as size of the loop but how does Golang know how many to run?
Also I now have cpu profile file. How can I use this to view it?
答案1
得分: 1
从TFM:
基准函数必须运行目标代码 b.N 次。基准包将会调整 b.N 的值,直到基准函数运行的时间足够长,可以可靠地计时。
英文:
From TFM:
> The benchmark function must run the target code b.N times. The benchmark package will vary b.N until the benchmark function lasts long enough to be timed reliably.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论