Skip to content

chore: enable CLI args filtering and support multiple benchmark classes - #14

Closed
sdwck wants to merge 1 commit into
Antyss77:masterfrom
sdwck:feature/benchmark-switcher
Closed

chore: enable CLI args filtering and support multiple benchmark classes#14
sdwck wants to merge 1 commit into
Antyss77:masterfrom
sdwck:feature/benchmark-switcher

Conversation

@sdwck

@sdwck sdwck commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Extracted this change into its own PR.
This replaces Benchmark.Run with Benchmark.FromAssembly.
This brings 2 DX improvements:

  • Passing args, it allows running specific benchmarks with dotnet run -c Release --project Benchmarks -- --filter *RemoveCharacters*
  • If new benchmark classes are added, they will automatically be picked up

@Antyss77

Copy link
Copy Markdown
Owner

Thanks for splitting this out. Tested it on our CI runner (non-interactive), and unfortunately BenchmarkSwitcher.Run(args, config) with empty args doesn't run anything — it just prints the "select a benchmark" prompt and exits, since there's no stdin to read from on a CI runner:

Available Benchmark:
#0 StringExtensionBenchmark
You should select the target benchmark(s)...

Our workflow calls dotnet run -c Release --project Benchmarks/Benchmarks.csproj with no arguments, and it needs to keep running every benchmark and printing the full summary table, exactly like before.

Could you make it default to running everything when no args are passed? Something like:

if (args.Length == 0)
{
    BenchmarkSwitcher.FromAssembly(typeof(StringExtensionBenchmark).Assembly).Run(new[] { "--filter", "*" }, config);
}
else
{
    BenchmarkSwitcher.FromAssembly(typeof(StringExtensionBenchmark).Assembly).Run(args, config);
}

That keeps the CLI filtering benefit for local use while keeping CI behavior identical to what it was before this PR. Happy to merge once that's confirmed working.

@sdwck sdwck closed this by deleting the head repository Aug 13, 2026
@sdwck

sdwck commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Hey! My bad, accidentally deleted my fork while doing some repository cleanup and it auto-closed the PR. Feel free to just copy paste your if/else snippet and push it to master, it's a great fix, and thanks for the code review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants