All skills
Skillintermediate
benchmark 1
Run benchmarks to measure and compare performance of code implementations.
Claude Code Knowledge Pack7/10/2026
Overview
Run benchmarks to measure and compare performance of code implementations.
Steps
- Identify the target for benchmarking:
- A specific function or module.
- Two implementations to compare (before/after refactor).
- An API endpoint under load.
- Set up the benchmark:
- Detect the runtime and available benchmarking tools.
- Node.js: Use
vitest benchor custom benchmark harness. - Python: Use
pytest-benchmarkortimeit. - Go: Use
testing.Bbuilt-in benchmarks. - Rust: Use
criterionor built-in#[bench].
- Configure benchmark parameters:
- Warm-up iterations to stabilize JIT and caches.
- Measurement iterations (minimum 100 for statistical significance).
- Input data size variations (small, medium, large).
- Run benchmarks and collect results:
- Operations per second.
- Average time per operation.
- Memory allocation per operation.
- P50, P95, P99 latencies.
- If comparing implementations, calculate relative performance difference.
- Generate a summary with statistical confidence.
Format
Benchmark: <name>
Iterations:
| Implementation | ops/sec | avg (ms) | P99 (ms) | mem (MB) |
|---------------|---------|----------|----------|----------|
| Original | 10,000 | 0.10 | 0.25 | 2.1 |
| Optimized | 25,000 | 0.04 | 0.08 | 1.8 |
Improvement: 2.5x faster, 14% less memory
Confidence: 95% (p < 0.05)
Rules
- Always include warm-up iterations before measurement.
- Run enough iterations for statistically significant results.
- Report standard deviation alongside averages.
- Benchmark on consistent hardware; note the environment.
- Disable garbage collection pauses during benchmarks where possible.