From d61b6c99a9acccf8203df4b1c12e21c36b67d6a4 Mon Sep 17 00:00:00 2001 From: Simon McKenna Date: Mon, 11 Mar 2024 18:25:48 +1030 Subject: [PATCH] Remove unnecessary settings --- Benchmarks.App/BenchmarkRunner.cs | 2 +- Benchmarks.App/Commands/BenchmarkCommand.cs | 4 ++-- .../{ListSettings.cs => BenchmarkSettings.cs} | 19 ++------------- Benchmarks.App/Commands/InfoCommand.cs | 4 ++-- Benchmarks.App/Commands/RunSettings.cs | 23 ------------------- Benchmarks.App/Commands/WorkflowCommand.cs | 7 ++++-- .../Menus/Selections/RunSelection.cs | 2 +- 7 files changed, 13 insertions(+), 48 deletions(-) rename Benchmarks.App/Commands/{ListSettings.cs => BenchmarkSettings.cs} (54%) delete mode 100644 Benchmarks.App/Commands/RunSettings.cs diff --git a/Benchmarks.App/BenchmarkRunner.cs b/Benchmarks.App/BenchmarkRunner.cs index eb1bb33..2a5f66e 100644 --- a/Benchmarks.App/BenchmarkRunner.cs +++ b/Benchmarks.App/BenchmarkRunner.cs @@ -11,7 +11,7 @@ public static IEnumerable RunAndBuildSummaries() } - public static IEnumerable RunAndBuildSummaries(ListSettings settings) + public static IEnumerable RunAndBuildSummaries(BenchmarkSettings settings) { var args = settings.BuildArgs(); var type = Reflection.GetBenchmarkTypes().First(type => type.Name == settings.Name); diff --git a/Benchmarks.App/Commands/BenchmarkCommand.cs b/Benchmarks.App/Commands/BenchmarkCommand.cs index 0bb70d6..ea2e731 100644 --- a/Benchmarks.App/Commands/BenchmarkCommand.cs +++ b/Benchmarks.App/Commands/BenchmarkCommand.cs @@ -1,11 +1,11 @@ namespace Benchmarks.App.Commands; -internal sealed class BenchmarkCommand : Command +internal sealed class BenchmarkCommand : Command { [SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")] public override int Execute( [NotNull] CommandContext context, - [NotNull] ListSettings settings) + [NotNull] BenchmarkSettings settings) { if (BenchmarkRunner.IsDebugConfiguration(settings.Debug)) { diff --git a/Benchmarks.App/Commands/ListSettings.cs b/Benchmarks.App/Commands/BenchmarkSettings.cs similarity index 54% rename from Benchmarks.App/Commands/ListSettings.cs rename to Benchmarks.App/Commands/BenchmarkSettings.cs index ef76aed..fddfbe9 100644 --- a/Benchmarks.App/Commands/ListSettings.cs +++ b/Benchmarks.App/Commands/BenchmarkSettings.cs @@ -1,6 +1,6 @@ namespace Benchmarks.App.Commands; -internal sealed class ListSettings : CommandSettings +internal sealed class BenchmarkSettings : CommandSettings { [Description("Benchmark name")] [CommandArgument(0, "[filter]")] @@ -10,10 +10,6 @@ internal sealed class ListSettings : CommandSettings [CommandOption("--debug")] public bool Debug { get; init; } - [Description("BenchmarkDotNet Exporters: GitHub/StackOverflow/RPlot/CSV/JSON/HTML/XML")] - [CommandOption("--exporters")] - public string? Exporters { get; init; } - public override ValidationResult Validate() { if (!Reflection.GetBenchmarkTypes().Any(type => type.Name == Name)) @@ -24,16 +20,5 @@ public override ValidationResult Validate() return ValidationResult.Success(); } - public string[] BuildArgs() - { - var args = new List { "--filter", $"*{Name}*" }; - - if (!string.IsNullOrEmpty(Exporters)) - { - args.Add("--exporters"); - args.Add(Exporters); - } - - return [.. args]; - } + public string[] BuildArgs() => ["--filter", $"*{Name}*"]; } diff --git a/Benchmarks.App/Commands/InfoCommand.cs b/Benchmarks.App/Commands/InfoCommand.cs index fec737a..88c56a1 100644 --- a/Benchmarks.App/Commands/InfoCommand.cs +++ b/Benchmarks.App/Commands/InfoCommand.cs @@ -1,11 +1,11 @@ namespace Benchmarks.App.Commands; -internal sealed class InfoCommand : Command +internal sealed class InfoCommand : Command { [SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")] public override int Execute( [NotNull] CommandContext context, - [NotNull] BenchmarkRunSettings settings) + [NotNull] BenchmarkSettings settings) { ConsoleWriter.WriteHeader(); diff --git a/Benchmarks.App/Commands/RunSettings.cs b/Benchmarks.App/Commands/RunSettings.cs deleted file mode 100644 index fdd11f9..0000000 --- a/Benchmarks.App/Commands/RunSettings.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Benchmarks.App.Commands; - -internal sealed class BenchmarkRunSettings : CommandSettings -{ - [Description("Name of benchmark")] - [CommandArgument(0, "[name]")] - public string Name { get; init; } = string.Empty; - - public override ValidationResult Validate() - { - if (string.IsNullOrWhiteSpace(Name)) - { - return ValidationResult.Error("No benchmark argument passed"); - } - - if (!Reflection.TryGetBenchmark(Name, out _)) - { - return ValidationResult.Error($"Benchmark not found '{Name}'"); - } - - return ValidationResult.Success(); - } -} \ No newline at end of file diff --git a/Benchmarks.App/Commands/WorkflowCommand.cs b/Benchmarks.App/Commands/WorkflowCommand.cs index 45c81bc..5659d52 100644 --- a/Benchmarks.App/Commands/WorkflowCommand.cs +++ b/Benchmarks.App/Commands/WorkflowCommand.cs @@ -5,14 +5,17 @@ internal sealed class WorkflowCommand : Command [SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")] public override int Execute([NotNull] CommandContext context) { + ConsoleWriter.WriteHeader(); + if (BenchmarkRunner.IsDebugConfiguration(true)) { return 1; } - var settings = new ListSettings { Exporters = "json" }; + // Exporters: GitHub/StackOverflow/RPlot/CSV/JSON/HTML/XML")] + var args = new[] { "--filter", $"Benchmarks*", "--exporters", "json" }; - BenchmarkRunner.RunBenchmarks(Reflection.GetBenchmarkTypes().ToArray(), settings.BuildArgs()); + BenchmarkRunner.RunBenchmarks([.. Reflection.GetBenchmarkTypes()], args); CombineBenchmarkResults(); diff --git a/Benchmarks.App/Menus/Selections/RunSelection.cs b/Benchmarks.App/Menus/Selections/RunSelection.cs index 573fa59..c274e5b 100644 --- a/Benchmarks.App/Menus/Selections/RunSelection.cs +++ b/Benchmarks.App/Menus/Selections/RunSelection.cs @@ -24,7 +24,7 @@ public override int Execute() return 1; } - var settings = new ListSettings { Name = Benchmark.Name }; + var settings = new BenchmarkSettings { Name = Benchmark.Name }; var summaries = BenchmarkRunner.RunAndBuildSummaries(settings); var builder = new SpectreReportBuilder(summaries); var report = builder.Build();