One of the great things about Go is that you can easily profile your code to find and optimize bottlenecks. Here are the steps that I went through to profile my Go apps.
// Inside test file
func BenchmarkBlah(b *testing.B) {
for n := 0; n < b.N; n++ {
// do some constant function here
}
}
go test -c
./blah.test -test.bench=. -test.cpuprofile=cpu.out
go tool pprof blah.test cpu.out
See the top 10 slowest cumulative functions
top10 -cum
Generate a svg with a graph of functions and dependencies
web
Inspect inside a function and see how long each line takes on average
list <function_name>
Same as list but displays the results through a webpage
weblist <function_name>