golang’s profiling tooling is superb and makes it a very exciting language for me. I temporarily ditched the Advent of Code problems to build a Mandelbrot Set viewer. This way I could learn several aspects of golang while producing pretty pictures which is always a good incentive for my ADHD brain. In this post I want to focus on profiling. An excellent resource is https://go.dev/blog/pprof

The route I followed was

  1. Write a BenchmarkXXX function in a test module invoking a function I was interested in.
  2. Save profiling data using go test -cpuprofile cpu.prof -memprofile mem.prof -bench .
  3. Inspect the profiles using go tool pprof cpu.prof

This last tool, pprof, which comes with go, is pretty nifty. From the interactive shell you can get a call graph (web <func_name>)

Once you’ve identified a function of interest, you can get a line-by-line analysis: list escape_number

It’s been a while since I profiled C++ code, but it wasn’t this easy by far.