andrewbrown-usda/aigb-skills-usda/performance-benchmarking
Claude Code and agent skill by andrewbrown-usda/aigb-skills-usda
- community
Checking that the SKILL.md file is still in the repository.
Design and run reproducible benchmarks. Use when measuring performance scaling, comparing branches, or analyzing speedup metrics.
Install
npx vskill@latest install andrewbrown-usda/aigb-skills-usda/performance-benchmarkingSKILL.md
The same SKILL.md was published earlier as andrewbrown-usda/aigb-skills-usda/performance-benchmarking.
Performance Benchmarking
Design and execute reproducible benchmarks to measure scaling, compare implementations, and analyze speedup.
Quick Start
Test a function's scaling with parameter n:
Run: Rscript bench.R
Benchmark Anatomy
Every reproducible benchmark has these components:
Warm-up Run
Run the function once before timing to stabilize JIT, caches, and memory allocation. Don't measure this run -- just let the system settle.
Multiple Timed Runs
Execute the function >=3 times per configuration. Record all times, report mean and standard deviation. Single-run benchmarks are noise.
Timeout Protection
Skip configurations that exceed 60 seconds per run. This prevents expensive branches (e.g., O(n^2) algorithms on master) from running excessively long tests.
CSV Output
Save results to CSV for comparison across runs and branches:
Visualization
Generate plots for scaling analysis. Log-log plots reveal asymptotic behavior (O(n), O(n^2), etc.).
Example 1: Hash Map Benchmarks
Functions: classify(), subst() -- value lookup and substitution Parameter: Lookup table size (n_lookup) Expected scaling: O(1) average with hash map, O(n^2) with nested loops
From archive benchmark_hash.R pattern:
Result interpretation: Flat slope = O(1), 45 deg slope = O(n), steep slope = O(n^2).
Example 2: Other Function Benchmarks
Functions: catalyze, unique, freq, crosstab Parameters: Category count, raster size, cardinality (each function differs) Timeout: 60s per run
From archive benchmark_other_functions.R pattern:
Branch Comparison Workflow
Compare performance across git branches:
Expected output:
Interpreting Results
Log-Log Scaling
Plot parameter (x-axis, log scale) vs. time (y-axis, log scale):
- 45 deg slope = O(n) scaling (linear growth)
- Flatter than 45 deg = Sublinear (better), e.g., O(log n)
- Steeper than 45 deg = Superlinear (worse), e.g., O(n^2)
Speedup Ratios
Report master_time / optimized_time:
| Ratio | Meaning | Action | |
|---|---|---|---|
| 0.9-1.1 | Noise | Ignore | |
| 1.2-2.0 | Measurable improvement | Accept | |
| 2.0-10.0 | Significant win | Highlight | |
| 10.0+ | Algorithmic breakthrough (e.g., O(n^2)->O(n)) | Celebrate |
When to Trust
- [OK] Reproducible: Same result across multiple runs
- [OK] Multiple runs: Report mean +/- SD from >=3 runs
- [OK] Consistent parameter sweep: No single outliers
- [FAIL] Single run: Noise, cache effects, system load vary
- [FAIL] No timeout: Extremely long runs suggest wrong algorithm
Troubleshooting
Installation Fails Between Branches
- Ensure no uncommitted changes:
git status - Manually install:
R CMD INSTALL .on each branch - Check build log for compiler errors
Out of Memory
- Reduce raster sizes (use 1000x1000 instead of 5000x5000)
- Reduce cardinality range (start at lower values)
- Run benchmarks individually, not all at once
Plots Not Generated
- Install ggplot2:
install.packages("ggplot2") - Check that benchmark results were saved to CSV
- Verify PNG/PDF output path is writable
Results Look Noisy
- Increase number of runs (try 5 instead of 3)
- Increase warm-up runs (let system stabilize longer)
- Run on dedicated machine (avoid background processes)
- Close other R sessions/large applications
Advanced: Multi-Branch Comparison
When comparing three or more branches, use a matrix approach:
Best Practices
Parameter Selection
Choose parameters that span realistic use cases:
- Small: Minimum viable input (sanity check)
- Medium: Typical production size (most important)
- Large: Stress test (catch O(n^2) issues)
Example for raster analysis: 100x100 (small), 1000x1000 (typical), 10000x10000 (large).
Warm-up Considerations
- JIT compilation (if applicable) needs 1-2 runs to warm up
- Memory allocation patterns settle after first run
- Cache state changes with size (cold cache vs. warm)
Use separate warm-up runs per parameter size, not global warm-up.
Error Bars Matter
Never report a single number. Always report mean +/- SD:
Version Control
Record which git commit you benchmarked:
Reproducibility Checklist
- [ ] Document exact machine specs (CPU, RAM, OS)
- [ ] Record git commit hashes
- [ ] Save all parameter values and time measurements to CSV
- [ ] Include warm-up count and timeout settings in output
- [ ] Note any background processes during benchmark
- [ ] Specify R version and package versions
Common Patterns from Production Benchmarks
Pattern 1: Scaling Analysis
Used to verify algorithmic improvements (e.g., O(n^2) -> O(n)):
Pattern 2: Regression Detection
Run nightly to catch performance degradation:
Pattern 3: Optimization Validation
Before/after comparison for specific fixes:
Pitfalls to Avoid
Pitfall 1: Micro-optimization over Macro
Chasing 5% speedups in rarely-called code. Measure first, optimize where it matters.
Pitfall 2: Ignoring System Load
Benchmarking on a busy machine. Results won't reproduce. Use a quiet machine.
Pitfall 3: Single-Parameter Sweep
Testing only one parameter value. True scaling analysis requires multiple points.
Pitfall 4: No Timeout
Letting slow algorithms run forever. Always cap benchmark runs at 60-120 seconds.
Pitfall 5: Comparing Different Datasets
Changing data between branches invalidates comparison. Use identical inputs.
Tools & Libraries
Base R
system.time()-- Measure elapsed timeRprof()-- Profile function calls (for bottleneck detection)
R Packages
microbenchmark-- Sub-millisecond precisionrbenchmark-- High-level benchmark interfaceggplot2-- Professional visualizations
External Tools
perf(Linux) -- CPU profilingvalgrind(Linux) -- Memory profilingInstruments(macOS) -- System-wide profiling
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/performance-benchmarking/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/andrewbrown-usda/aigb-skills-usda/performance-benchmarking)