diff --git a/Benchmarks.App/Benchmark.cs b/Benchmarks.App/Benchmark.cs index 0eeb2ed..32eb9c9 100644 --- a/Benchmarks.App/Benchmark.cs +++ b/Benchmarks.App/Benchmark.cs @@ -8,9 +8,6 @@ internal record Benchmark( internal static partial class BenchmarkExtensions { - internal static bool HasSimilarNameAndDescription(this Benchmark benchmark) => - benchmark.Description.ReplaceWhitespace(string.Empty) == benchmark.Name; - internal static Table Markup(this Benchmark benchmark) { var table = new Table @@ -42,10 +39,4 @@ internal static Table Markup(this Benchmark benchmark) return table; } - - [GeneratedRegex(@"\s+")] - private static partial Regex WhitespaceRegex(); - private static readonly Regex MatchWhitespace = WhitespaceRegex(); - private static string ReplaceWhitespace(this string input, string replacement) => - MatchWhitespace.Replace(input, replacement); } \ No newline at end of file diff --git a/Benchmarks.App/BenchmarkRunner.cs b/Benchmarks.App/BenchmarkRunner.cs index 2a5f66e..4b4cf0b 100644 --- a/Benchmarks.App/BenchmarkRunner.cs +++ b/Benchmarks.App/BenchmarkRunner.cs @@ -4,7 +4,7 @@ internal static class BenchmarkRunner { public static IEnumerable RunAndBuildSummaries() { - var args = new[] { "--filter", $"Benchmarks*" }; + var args = new[] { "--filter", "Benchmarks*" }; var types = Reflection.GetBenchmarkTypes().ToArray(); return RunAndBuildSummaries(types, args); @@ -21,7 +21,6 @@ public static IEnumerable RunAndBuildSummaries(BenchmarkSettings settin public static IEnumerable RunAndBuildSummaries(Type[] benchmarkTypes, string[] args) { - AnsiConsole.Cursor.Move(CursorDirection.Up, 1); Console.SetOut(TextWriter.Null); @@ -45,13 +44,10 @@ public static IEnumerable RunBenchmarks(Type[] types, string[] args) => internal static bool IsDebugConfiguration(bool warnRatherThanFail = false) { - // ReSharper disable once JoinDeclarationAndInitializer - bool debug; + var debug = false; #if DEBUG debug = true; -#else - debug = false; #endif if (!debug) diff --git a/Benchmarks.App/Commands/BenchmarkCommand.cs b/Benchmarks.App/Commands/BenchmarkCommand.cs index ea2e731..b87dd84 100644 --- a/Benchmarks.App/Commands/BenchmarkCommand.cs +++ b/Benchmarks.App/Commands/BenchmarkCommand.cs @@ -2,10 +2,7 @@ internal sealed class BenchmarkCommand : Command { - [SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")] - public override int Execute( - [NotNull] CommandContext context, - [NotNull] BenchmarkSettings settings) + public override int Execute(CommandContext context, BenchmarkSettings settings) { if (BenchmarkRunner.IsDebugConfiguration(settings.Debug)) { diff --git a/Benchmarks.App/Commands/BenchmarkSettings.cs b/Benchmarks.App/Commands/BenchmarkSettings.cs index fddfbe9..e2e4860 100644 --- a/Benchmarks.App/Commands/BenchmarkSettings.cs +++ b/Benchmarks.App/Commands/BenchmarkSettings.cs @@ -12,7 +12,12 @@ internal sealed class BenchmarkSettings : CommandSettings public override ValidationResult Validate() { - if (!Reflection.GetBenchmarkTypes().Any(type => type.Name == Name)) + if (string.IsNullOrWhiteSpace(Name)) + { + return ValidationResult.Error($"Benchmark name required"); + } + + if (Reflection.GetBenchmarkTypes().All(type => type.Name != Name)) { return ValidationResult.Error($"Benchmark not found {Name}"); } diff --git a/Benchmarks.App/Commands/InfoCommand.cs b/Benchmarks.App/Commands/InfoCommand.cs index 88c56a1..d623262 100644 --- a/Benchmarks.App/Commands/InfoCommand.cs +++ b/Benchmarks.App/Commands/InfoCommand.cs @@ -2,10 +2,7 @@ internal sealed class InfoCommand : Command { - [SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")] - public override int Execute( - [NotNull] CommandContext context, - [NotNull] BenchmarkSettings settings) + public override int Execute(CommandContext context, BenchmarkSettings settings) { ConsoleWriter.WriteHeader(); diff --git a/Benchmarks.App/Commands/ListCommand.cs b/Benchmarks.App/Commands/ListCommand.cs index 71b8ad2..bdd4745 100644 --- a/Benchmarks.App/Commands/ListCommand.cs +++ b/Benchmarks.App/Commands/ListCommand.cs @@ -2,8 +2,7 @@ internal sealed class ListCommand : Command { - [SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")] - public override int Execute([NotNull] CommandContext context) + public override int Execute(CommandContext context) { ConsoleWriter.WriteHeader(); diff --git a/Benchmarks.App/Commands/WorkflowCommand.cs b/Benchmarks.App/Commands/WorkflowCommand.cs index 8093ffa..5872d21 100644 --- a/Benchmarks.App/Commands/WorkflowCommand.cs +++ b/Benchmarks.App/Commands/WorkflowCommand.cs @@ -2,8 +2,7 @@ internal sealed class WorkflowCommand : Command { - [SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")] - public override int Execute([NotNull] CommandContext context) + public override int Execute(CommandContext context) { if (BenchmarkRunner.IsDebugConfiguration(true)) { diff --git a/Benchmarks.App/Menus/BenchmarkMenu.cs b/Benchmarks.App/Menus/BenchmarkMenu.cs index d86bbae..21b317b 100644 --- a/Benchmarks.App/Menus/BenchmarkMenu.cs +++ b/Benchmarks.App/Menus/BenchmarkMenu.cs @@ -2,7 +2,7 @@ internal sealed class BenchmarkMenu : MenuBase { - private Benchmark Benchmark { get; init; } + private Benchmark Benchmark { get; } public BenchmarkMenu(Benchmark benchmark) { diff --git a/Benchmarks.App/Menus/MainMenu.cs b/Benchmarks.App/Menus/MainMenu.cs index ec24b27..9304616 100644 --- a/Benchmarks.App/Menus/MainMenu.cs +++ b/Benchmarks.App/Menus/MainMenu.cs @@ -12,6 +12,7 @@ public MainMenu() new ExitSelection(4) { ExitApp = true } }; } + public override int Render() { var selected = Choices.First(); diff --git a/Benchmarks.App/Menus/Selections/ListSelection.cs b/Benchmarks.App/Menus/Selections/ListSelection.cs index 0ebb907..1786e27 100644 --- a/Benchmarks.App/Menus/Selections/ListSelection.cs +++ b/Benchmarks.App/Menus/Selections/ListSelection.cs @@ -30,7 +30,11 @@ public override int Execute() // Would also be good to filter by keyboard input e.g. Esc to return to main menu prompt.AddChoice(new Benchmark("Exit")); - var table = new Table { Border = TableBorder.Simple }; + var table = new Table + { + Border = TableBorder.Simple, + BorderStyle = new Style(foreground: Color.Grey) + }; table.AddColumns("Benchmark", "Description", "Category"); table.Columns[0].Width = padding.NamePad; table.Columns[1].Width = padding.DescriptionPad; diff --git a/Benchmarks.App/Reflection.cs b/Benchmarks.App/Reflection.cs index 5e8660b..75154ab 100644 --- a/Benchmarks.App/Reflection.cs +++ b/Benchmarks.App/Reflection.cs @@ -34,7 +34,6 @@ private static Benchmark GetBenchmark(MemberInfo memberInfo) attribute.Category); } - public static IEnumerable GetBenchmarkTypes() => typeof(GuidPrimaryKey).Assembly .GetTypes() diff --git a/Benchmarks.App/SpectreLogger.cs b/Benchmarks.App/SpectreLogger.cs index 973fab8..19b9fc2 100644 --- a/Benchmarks.App/SpectreLogger.cs +++ b/Benchmarks.App/SpectreLogger.cs @@ -4,20 +4,11 @@ internal sealed class SpectreLogger : ILogger { public static readonly SpectreLogger Logger = new(); - public void Write(LogKind logKind, string text) - { - Markup(logKind, text, writeLine: false); - } + public void Write(LogKind logKind, string text) => Markup(logKind, text, writeLine: false); - public void WriteLine() - { - AnsiConsole.WriteLine(); - } + public void WriteLine() => AnsiConsole.WriteLine(); - public void WriteLine(LogKind logKind, string text) - { - Markup(logKind, text, writeLine: true); - } + public void WriteLine(LogKind logKind, string text) => Markup(logKind, text, writeLine: true); public void Flush() { diff --git a/Benchmarks/GuidPrimaryKey.cs b/Benchmarks/GuidPrimaryKey.cs index 43a05fb..515721e 100644 --- a/Benchmarks/GuidPrimaryKey.cs +++ b/Benchmarks/GuidPrimaryKey.cs @@ -54,7 +54,7 @@ public async Task Setup() [Benchmark] public async Task InsertGuidPrimaryKeyPostgres() { - using var dbContext = CreateDbContext(DbServer.Postgres); + await using var dbContext = CreateDbContext(DbServer.Postgres); await dbContext.Database.MigrateAsync(); await dbContext.ClusteredIndexes.AddRangeAsync(CreateEntities()); await dbContext.SaveChangesAsync(); @@ -63,7 +63,7 @@ public async Task InsertGuidPrimaryKeyPostgres() [Benchmark] public async Task InsertGuidPrimaryKeyWithClusteredIndexSqlServer() { - using var dbContext = CreateDbContext(DbServer.SqlServer); + await using var dbContext = CreateDbContext(DbServer.SqlServer); await dbContext.Database.MigrateAsync(); await dbContext.ClusteredIndexes.AddRangeAsync(CreateEntities()); await dbContext.SaveChangesAsync(); @@ -72,7 +72,7 @@ public async Task InsertGuidPrimaryKeyWithClusteredIndexSqlServer() [Benchmark] public async Task InsertGuidPrimaryKeyWithNonClusteredIndexSqlServer() { - using var dbContext = CreateDbContext(DbServer.SqlServer); + await using var dbContext = CreateDbContext(DbServer.SqlServer); await dbContext.Database.MigrateAsync(); await dbContext.NonClusteredIndexes.AddRangeAsync(CreateEntities()); await dbContext.SaveChangesAsync();