Essential Go Profiling using go tool pprof  Suggest an edit

Using Benchmarks to Create Profile

For a non-main packages as well as main, instead of adding flags inside the code, write benchmarks in the test package , for example:

func BenchmarkHello(b *testing.B) {
    for i := 0; i < b.N; i++ {

Then run the test with the profile flag

go test -cpuprofile -bench=.

And the benchmarks will be run and create a prof file with filename (in the above example).

  ↑ ↓ to navigate     ↵ to select     Esc to close