Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Benchmarking & Profiling | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 12 of 60

·Go

Benchmarking & Profiling

15 minutes

Course progress20%

Benchmarking

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

Benchmarks live in _test.go files and use the *testing.B argument.

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

Run with the -bench flag:

$ go test -bench=.

Profiling CPU & Memory

$ go test -cpuprofile=cpu.out -memprofile=mem.out ./...
$ go tool pprof cpu.out

Inside the pprof REPL you can type top, list Fib, web (requires Graphviz).

Race Detector

Detect data races in concurrent code:

$ go run -race main.go

Info

Profiling works best on compiled binaries (go build) rather than go run.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonTesting in Go: The `testing` PackageContinue to lesson 13Concurrency Primer: GoroutinesBack to Go Programming Bootcamp curriculum