yi-jiayu / blog

My blog
https://blog.jiayu.co
1 stars 0 forks source link

2019/05/benchmarking-go-code/ #5

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Benchmarking Go code - Jiayu's Blog

I recently attended GopherCon Singapore 2019, and one of the talks was about optimising Go code, by Daniel Martí. I managed to find a set of his slides from a previous conference that he gave the same talk at: Optimizing Go code without a blindfold Daniel Martí at dotGo 2019 https://www.dotconferences.com/2019/03/daniel-marti-optimizing-go-code-without-a-blindfold My main takeaway from his talk the usage of benchstat for computing statistics from multiple runs of go test -bench, which helps to remove noise and identify statistically significant results:

https://blog.jiayu.co/2019/05/benchmarking-go-code/

chmike commented 2 years ago

Unfortunately, the example does not work since the output of go test -bench=xxx is something like this:

3 expect 0.000000, got -0.300000goos: linux goarch: amd64 pkg: dptopx cpu: Intel(R) Core(TM) i5-3340 CPU @ 3.10GHz BenchmarkRoundGIO-4 297134211 3.930 ns/op PASS ok dptopx 1.587s

Also the for loop is not need since go test has now a -count=xx argument.

Unfortunately, if I strip off everything except the Benchmark lines, the benchstat command doesn’t output anything. Note that in the benchmark --help, the old.txt comes first and new.txt second. You reversed them in your blog post.