Profiling is a process of dynamic program analysis that measures various values related to program execution in order to give you a better understanding of the behavior of your program. In this section, you are going to learn how to profile Go code in order to understand your code better and improve its performance. Sometimes, code profiling can even reveal bugs!
First, we are going to use the command-line interface of the Go profiler. Then, we will use the web interface of the Go profiler.
The single most important thing to remember is that if you want to profile Go code, you will need to import the runtime/pprof standard Go package, either directly or indirectly. You can find the help page of the pprof tool by executing the go tool pprof -help command, which will generate lots of output.