对 Go 程序进行可靠的性能测试[Image](/uploads/documents/2/a/8/2/2a82c2fa12e5c829b2b30854f6733736/p1_1.jpg) ## 主要内容 • 可靠的测试环境 • benchstat • 例子与实践 ☐ 例1: 对代码块进行性能调优 ☐ 例2: Benchmark 的正确性分析 ☐ 例3: 其他的影响因素 • 假设检验的原理 • 局限与应对措施 • 总结 ## test -bench=. ## benchstat benchstat 的功能非常简单,作用只是对性能测试结果进行统计分析,对测量结果进行假设检验,从而消除结果的观测误差(observational error)。 $ go get golang.org/x/perf/cmd/benchstat $ benchstat --help usage: benchstat [options] old.txt utest/ttest/none(默认 utest) -geomean 输出几何平均值 -sort order 对结果进行排序:[-]delta, [-]name, none(默认值 none) ## benchstat 的原理: 异常值消除+假设检验 当对一个性能基准测试 B 结果反复执行 n 次后,就能得到 $ b_{1} $ ,…, $ b_{n} $ 个不同的结果;在优化代码后,还能得到另外 m0 码力 | 37 页 | 1.23 MB | 2 年前3
如何向Go官方提交代码-蒙卓不要提中文 issue 3. 事实为依据 a. 资料要有出处 b. benchstat 要带上 4. 政治正确 ## 如何交流 1. 开发团队 2. 英语,英语,英语 a. 不要提中文issue 3. 事实为依据 a. 资料要有出处 b. benchstat 要带上 4. 政治正确 5. 俗语 a. LGTM: Looks0 码力 | 38 页 | 5.95 MB | 2 年前3
How and When You
Should Measure CPU
Overhead of eBPF
Programs## ebpfbench API Augments testing.B Outputs results in go benchmark format Can be used with benchstat and other tools ## ☀️ ☀️ ☁️ func BenchmarkEBPF(b *testing.B) { // setup ebpf benchmark0 码力 | 20 页 | 2.04 MB | 1 年前3
1.1.3 The State Of Go 2023“gopherchina”:2023} ’ alt=‘OCR图片’/> 增加log/slog slog benchmarkbenchstat zapbenchmarks/zap.bench slog.bench name old time/op new time/o 0 码力 | 26 页 | 1.90 MB | 1 月前3共 4 条- 1













