Using Benchmarks to Create Profile

suggest change

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).

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents