Posted on 13 Jan, 2024
Install the perf
utility tools that help in analyzing the benchmarks.
go install golang.org/x/perf/cmd/...@latest
Close all other applications including browsers & background apps like docker to get accurate results.
Run benchmarks
go test -bench=BenchmarkMyFunction -benchmem -count=10 | tee old_benchmark.txt
Change the implementation and run the benchmarks again
go test -bench=BenchmarkMyFunction -benchmem -count=10 | tee new_benchmark.txt
Compare the benchmarks
benchstat old_benchmark.txt new_benchmark.txt