NetFabric/NetFabric.Numerics / .agents/skills/dotnet-benchmarking
dotnet-benchmarking
VerifiedMeasure C#/.NET performance with BenchmarkDotNet instead of stopwatches. USE FOR: BenchmarkDotNet console project setup, BenchmarkSwitcher.FromAssembly; [Benchmark]/[Benchmark(Baseline = true)]; [Params]; [GlobalSetup]/[GlobalCleanup]; [MemoryDiagnoser] allocation columns; [BenchmarkCategory]/[GroupBenchmarksBy]/[CategoriesColumn]/[HideColumns]; reading Mean/Error/StdDev/Ratio/Allocated results and BenchmarkDotNet.Artifacts output; avoiding dead-code elimination via return values; comparing .NET runtimes/versions via AddJob/WithRuntime; ManualConfig job classes with WithEnvironmentVariable and RatioStyle.Trend; testing environment-variable variants via .runsettings, `dotnet test -e`/`-s`, Visual Studio run-settings. DO NOT USE FOR: SIMD API selection (dotnet-simd, has its own SIMD-width benchmarking config); LINQ/enumerable tradeoffs (dotnet-enumerable); generic math (dotnet-generic-math).
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.6 KB |
| references/comparing-configurations.md | markdown | 2.8 KB |
| references/interpreting-results.md | markdown | 2.7 KB |
| references/runtime-variant-testing.md | markdown | 1.8 KB |
| references/writing-benchmarks.md | markdown | 3.2 KB |
references/runtime-variant-testing.md
View on GitHub# Testing Under Environment-Variable Variants
Some behavior (feature flags, hardware-capability toggles, GC modes, ...) only differs when a specific environment variable is set. Cover every relevant variant in unit tests too, not just benchmarks — even code that doesn't read the variable directly may depend on something that does.
## `.runsettings` Files
Create one file per scenario and set variables under `RunConfiguration/EnvironmentVariables`:
```xml
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<SOME_FEATURE_FLAG>0</SOME_FEATURE_FLAG>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
```
Naming convention: prefix files with `_` (e.g. `_Scalar.runsettings`) so they sort together and stand out in a file list among regular source files.
## Visual Studio
`Test > Configure Run Settings > Select Solution Wide runsettings File`, then pick the file for the scenario to run. Visual Studio auto-detects a single `.runsettings` file in the solution but requires manual selection when multiple exist.
## Command Line
`dotnet test` supports environment variables inline or via a settings file — useful for CI pipelines and editors without Visual Studio's run-settings picker:
```shell
# Inline, one variable at a time
dotnet test -e:SOME_FEATURE_FLAG=0
# Via a .runsettings file
dotnet test -s:_Scalar.runsettings
```
`-e`/`--environment` and `-s`/`--settings` can both be repeated/combined as needed.
For the specific `DOTNET_Enable*` variables that control SIMD width (`DOTNET_EnableHWIntrinsic`, `DOTNET_EnableAVX2`, `DOTNET_EnableAVX512`, ...) and the `_Scalar`/`_Vector128`/`_Vector256`/`_Vector512` file set built from them, see the `dotnet-simd` skill's `testing-and-benchmarking.md` reference.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |