Back to Concepts Roadmap
🟨 Level 10 — Build & Deploy
Tooling & DevOps

Performance Profiling (pprof & Race)

Finding memory leaks, CPU bottlenecks, and data races with pprof, benchmarks, and -race.

Real-World Analogy (Mental Model)

An ultrasound sensor and speedometer plugged into an engine during a high-speed test track run.

Key Concepts & Rules To Remember

  • `go test -bench=. -benchmem` measures nanoseconds per operation and bytes allocated.
  • `go test -race` detects concurrent data race bugs.
  • `pprof` generates visual flame graphs of CPU and heap memory usage.
Step-by-Step Code

1. Understanding Performance Profiling (pprof & Race)

Finding memory leaks, CPU bottlenecks, and data races with pprof, benchmarks, and -race. In Go, performance profiling (pprof & race) is designed around clarity and high runtime efficiency.

example.goGo 1.24+
func BenchmarkFib(b *testing.B) {
    for i := 0; i < b.N; i++ {
        Fib(20)
    }
}

Common Beginner Pitfalls & Mistakes

Mistake: Misusing performance profiling (pprof & race) without understanding its memory or concurrency semantics.
✅ Correct Way: Always follow standard Go idioms and verify with tests.
Self Assessment

Knowledge Check

Verify your understanding with these interactive practice questions.

Quizzes

Quick checks for understanding

Multiple-choice with inline explanations—expand to see why.

What is the primary concept behind Performance Profiling (pprof & Race)?

Finished this lesson?

Mark it as complete to track your overall Go mastery.