go get golang.org/x/tools/cmd/benchcmp
write a benchmark for the function:
package main
import (
"testing"
)
func BenchmarkMain(b *testing.B) {
main()
}
run the benchmark as:
go test -count=1 -benchmem -run=^$ github.com/zyxan/some_go_project -bench ^BenchmarkMain$ | tee ~/Desktop/old.out
keep the old.txt
file safe while you "improve" your implementation. Once you have something you want to compare, run the benchmark again only this time piping it into ~/Desktop/new.out
Compare results with benchcmp, seeing something like:
benchcmp old.txt new.txt
benchmark old ns/op new ns/op delta
BenchmarkMain-8 16658672431 12593963945 -24.40%
benchmark old allocs new allocs delta
BenchmarkMain-8 3679046 4220014 +14.70%
benchmark old bytes new bytes delta
BenchmarkMain-8 157065264 3379300000 +2051.53%