Skip to content

NetFabric/NetFabric.Numerics / .agents/skills/dotnet-benchmarking

dotnet-benchmarking

Verified

Measure 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).

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.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall