Profiling Your Tool

Powerful Command-Line Applications in Go — by Ricardo Gerardi (52 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Benchmarking Your Tool | TOC | Reducing Memory Allocation 👉

Go provides several tools to help you analyze your programs for performance-related issues. You’ve already seen the benchmarking feature and how you can use it to accurately determine how fast your programs execute. In addition to benchmarks, Go provides two analytical tools to help you find contentions or bottlenecks in your programs: the profiling and tracing tools.

You’ll explore the tracing tool in Tracing Your Tool. For now, let’s dive into the profiling tool.

The Go profiler shows you a breakdown of where your program spends its execution time. By running the profiler, you can determine which functions consume most of the program’s execution time and target them for optimization.

You have two ways to enable profiling on your programs: by adding code directly to your program or by running the profiler integrated with the testing and benchmarking tools. The first approach requires that you maintain additional code in your application and control the profiling execution yourself. The second approach tends to be easier since it’s already integrated with the benchmark tool, so you don’t need to add any more code to your program. You’ll use this approach in this example since you already have a benchmark available.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.