Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
cxuu avatar

Go Performance

  • 939 installs
  • 137 repo stars
  • Updated June 20, 2026
  • cxuu/golang-skills

Go Performance is a Claude Code skill that teaches developers to write, run, and interpret Go benchmarks measuring CPU time and memory usage before shipping backend Go services.

About

Go Performance is a Claude Code skill for Go backend engineers who need disciplined benchmark methodology instead of guesswork profiling. It documents how to write Benchmark functions in _test.go files using testing.B, loop with b.N, prevent compiler dead-code elimination, and call b.ResetTimer after setup. The skill covers comparing strconv versus fmt approaches, reading ns/op and allocation lines, and using benchstat or benchcmp workflows to judge regressions. Developers reach for Go Performance when optimizing hot paths, validating micro-optimizations, or establishing a repeatable benchmark suite before release.

  • Teaches correct use of testing.B with b.N loop control and result assignment to prevent compiler optimization
  • Explains b.ResetTimer(), b.ReportAllocs(), and sub-benchmarks with b.Run()
  • Provides exact go test commands including -benchmem and -count=10 for statistical significance
  • Covers both writing benchmarks in _test.go files and running them with memory and allocation tracking
  • Delivers reusable benchmark methodology that improves Go performance measurement accuracy

Go Performance by the numbers

  • 939 all-time installs (skills.sh)
  • +39 installs in the week ending Aug 5, 2026 (Skillselion tracking)
  • Ranked #546 of 2,153 Testing & QA skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/cxuu/golang-skills --skill go-performance

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs939
repo stars137
Security audit3 / 3 scanners passed
Last updatedJune 20, 2026
Repositorycxuu/golang-skills

How do you benchmark Go code correctly?

Write, run, and interpret Go benchmarks that measure performance and memory usage before shipping backend code.

Who is it for?

Go backend engineers optimizing hot paths who need reproducible testing.B benchmarks and clear before-and-after performance reads.

Skip if: Teams not using Go or developers who only need distributed tracing and production APM without local micro-benchmarks.

When should I use this skill?

The user asks to benchmark Go code, write Benchmark functions, measure allocations, compare strconv vs fmt performance, or interpret go test -bench results.

What you get

Go _test.go benchmark functions, benchstat comparisons, and interpreted ns/op and memory allocation reports.

  • benchmark functions
  • bench comparison reports

Files

SKILL.mdMarkdownGitHub ↗

Go Performance Patterns

Resource Routing

  • scripts/bench-compare.sh - Run when comparing benchmark results, saving baselines, or producing JSON benchmark metadata.
  • references/BENCHMARKS.md - Read when writing benchmarks, using benchstat, or profiling with pprof.
  • references/STRING-OPTIMIZATION.md - Read when optimizing string conversion, concatenation, or byte/string boundaries.

Performance-specific guidelines apply only to the hot path. Don't prematurely optimize—focus these patterns where they matter most.

---

Prefer strconv over fmt

When converting primitives to/from strings, strconv is faster than fmt:

s := strconv.Itoa(rand.Int()) // ~2x faster than fmt.Sprint()
ApproachSpeedAllocations
fmt.Sprint143 ns/op2 allocs/op
strconv.Itoa64.2 ns/op1 allocs/op

---

Avoid Repeated String-to-Byte Conversions

Convert a fixed string to []byte once outside the loop:

data := []byte("Hello world")
for b.Loop() { // Go 1.24+; use b.N loops only for older Go
    w.Write(data) // ~7x faster than []byte("...") each iteration
}

---

Prefer Specifying Container Capacity

Specify container capacity where possible to allocate memory up front. This minimizes subsequent allocations from copying and resizing as elements are added.

Map Capacity Hints

Provide capacity hints when initializing maps with make():

m := make(map[string]os.DirEntry, len(files))

Note: Unlike slices, map capacity hints do not guarantee complete preemptive allocation—they approximate the number of hashmap buckets required.

Slice Capacity

Provide capacity hints when initializing slices with make(), particularly when appending:

data := make([]int, 0, size)

Unlike maps, slice capacity is not a hint—the compiler allocates exactly that much memory. Subsequent append() operations incur zero allocations until capacity is reached.

ApproachTime (100M iterations)
No capacity2.48s
With capacity0.21s

The capacity version is ~12x faster due to zero reallocations during append.

---

Pass Values

Don't pass pointers as function arguments just to save a few bytes. If a function refers to its argument x only as *x throughout, then the argument shouldn't be a pointer.

func process(s string) { // not *string — strings are small fixed-size headers
    fmt.Println(s)
}

Common pass-by-value types: string, io.Reader, small structs.

Exceptions:

  • Large structs where copying is expensive
  • Small structs that might grow in the future

---

String Concatenation

Choose the right strategy based on complexity:

MethodBest For
+Few strings, simple concat
fmt.SprintfFormatted output with mixed types
strings.BuilderLoop/piecemeal construction
strings.JoinJoining a slice
Backtick literalConstant multi-line text

---

Benchmarking and Profiling

Always measure before and after optimizing. Use Go's built-in benchmark framework and profiling tools.

go test -bench=. -benchmem -count=10 ./...
Validation: After applying optimizations, run bash scripts/bench-compare.sh to measure the actual impact. Only keep optimizations with measurable improvement.

---

Quick Reference

PatternBadGoodImprovement
Int to stringfmt.Sprint(n)strconv.Itoa(n)~2x faster
Repeated []byte[]byte("str") in loopConvert once outside~7x faster
Map initializationmake(map[K]V)make(map[K]V, size)Fewer allocs
Slice initializationmake([]T, 0)make([]T, 0, cap)~12x faster
Small fixed-size args*string, *io.Readerstring, io.ReaderNo indirection
Simple string joins1 + " " + s2(already good)Use + for few strings
Loop string buildRepeated +=strings.BuilderO(n) vs O(n²)

---

Related Skills

  • Data structures: See go-data-structures when choosing between slices, maps, and arrays, or understanding allocation semantics
  • Declaration patterns: See go-declarations when using make with capacity hints or initializing maps and slices
  • Concurrency: See go-concurrency when parallelizing work across goroutines or using sync.Pool for buffer reuse
  • Style principles: See go-style-core when deciding whether an optimization is worth the readability cost

Related skills

How it compares

Pick Go Performance over generic profiling guides when the task is authoring and reading testing.B micro-benchmarks in Go _test.go files.

FAQ

How does Go Performance teach benchmark writing?

Go Performance teaches Go developers to place Benchmark-prefixed functions in _test.go files, loop with testing.B's b.N, assign outputs to avoid dead-code elimination, and call b.ResetTimer after setup so measurements cover only the hot path.

When should Go developers use the Go Performance skill?

Go developers should use Go Performance before shipping backend changes when they need reproducible CPU and memory benchmarks, want to compare implementations like strconv versus fmt, or must interpret ns/op and allocation lines for regression decisions.

Is Go Performance safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Testing & QAbackendtesting

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.