Skip to content
Back to skills

Benchmarks

ASecurity

Benchmark patterns for performance testing

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added February 7, 2026
testinggobashtestingperformance

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add JamesPrial/claudefiles --skill benchmarks --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Benchmarks?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Benchmarks
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jamesprial-benchmarks/badge)](https://www.skillsdirectory.com/skills/jamesprial-benchmarks)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: go-testing-benchmarks
description: Benchmark patterns for performance testing
---

# Benchmarks

Measure function performance with benchmark tests.

## CORRECT

```go
func Benchmark_Fibonacci(b *testing.B) {
    for i := 0; i < b.N; i++ {
        Fibonacci(10)
    }
}

func Benchmark_Fibonacci_Cases(b *testing.B) {
    cases := []struct {
        name string
        n    int
    }{
        {name: "small", n: 10},
        {name: "medium", n: 20},
        {name: "large", n: 30},
    }

    for _, bc := range cases {
        b.Run(bc.name, func(b *testing.B) {
            for i := 0; i < b.N; i++ {
                Fibonacci(bc.n)
            }
        })
    }
}

func Benchmark_StringConcat(b *testing.B) {
    b.ResetTimer()  // Exclude setup time
    for i := 0; i < b.N; i++ {
        _ = "hello" + "world"
    }
}
```

**Run benchmarks:**
```bash
go test -bench=. -benchmem
```

**Why:**
- b.N adjusted automatically for stable timing
- Sub-benchmarks compare variations
- b.ResetTimer() excludes setup
- -benchmem shows allocation stats

## WRONG

```go
func Benchmark_Fibonacci(b *testing.B) {
    Fibonacci(10)  // Missing loop
}

func Benchmark_NoReset(b *testing.B) {
    // Expensive setup
    data := generateLargeData()
    // Missing b.ResetTimer()
    for i := 0; i < b.N; i++ {
        Process(data)
    }
}
```

**Problems:**
- No b.N loop = invalid benchmark
- Setup time included in measurement
- Inaccurate performance results

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.