You can refer to the 2 following links:
We will leverage on Go language's built-in tools for generating benchmarks.
We will then use pprof to profile the code.
go install github.com/google/pprof@latest
The code used to run the benchmark is available here
go test -v -benchmem -cpuprofile cpu.prof -bench=. ./...
pprof -http=localhost:5000 cpu.prof
This command starts a web server listening on http=localhost:5000
Feel free to use a different port number.
Open http=localhost:5000
in a browser and go through execution details
to identify parts of the code to optimize.
You can use pprof's VIEW
menu to choose which view to display.
Once you have a new improved version ot the code, restart from step 2.