Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
si618 committed Mar 11, 2024
1 parent 240be18 commit d98a041
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 46 deletions.
9 changes: 0 additions & 9 deletions Benchmarks.App/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
8 changes: 2 additions & 6 deletions Benchmarks.App/BenchmarkRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ internal static class BenchmarkRunner
{
public static IEnumerable<Summary> RunAndBuildSummaries()
{
var args = new[] { "--filter", $"Benchmarks*" };
var args = new[] { "--filter", "Benchmarks*" };
var types = Reflection.GetBenchmarkTypes().ToArray();

return RunAndBuildSummaries(types, args);
Expand All @@ -21,7 +21,6 @@ public static IEnumerable<Summary> RunAndBuildSummaries(BenchmarkSettings settin

public static IEnumerable<Summary> RunAndBuildSummaries(Type[] benchmarkTypes, string[] args)
{

AnsiConsole.Cursor.Move(CursorDirection.Up, 1);

Console.SetOut(TextWriter.Null);
Expand All @@ -45,13 +44,10 @@ public static IEnumerable<Summary> 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)
Expand Down
5 changes: 1 addition & 4 deletions Benchmarks.App/Commands/BenchmarkCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

internal sealed class BenchmarkCommand : Command<BenchmarkSettings>
{
[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))
{
Expand Down
7 changes: 6 additions & 1 deletion Benchmarks.App/Commands/BenchmarkSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand Down
5 changes: 1 addition & 4 deletions Benchmarks.App/Commands/InfoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

internal sealed class InfoCommand : Command<BenchmarkSettings>
{
[SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")]
public override int Execute(
[NotNull] CommandContext context,
[NotNull] BenchmarkSettings settings)
public override int Execute(CommandContext context, BenchmarkSettings settings)
{
ConsoleWriter.WriteHeader();

Expand Down
3 changes: 1 addition & 2 deletions Benchmarks.App/Commands/ListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions Benchmarks.App/Commands/WorkflowCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks.App/Menus/BenchmarkMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

internal sealed class BenchmarkMenu : MenuBase
{
private Benchmark Benchmark { get; init; }
private Benchmark Benchmark { get; }

public BenchmarkMenu(Benchmark benchmark)
{
Expand Down
1 change: 1 addition & 0 deletions Benchmarks.App/Menus/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public MainMenu()
new ExitSelection(4) { ExitApp = true }
};
}

public override int Render()
{
var selected = Choices.First();
Expand Down
6 changes: 5 additions & 1 deletion Benchmarks.App/Menus/Selections/ListSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion Benchmarks.App/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ private static Benchmark GetBenchmark(MemberInfo memberInfo)
attribute.Category);
}


public static IEnumerable<Type> GetBenchmarkTypes() =>
typeof(GuidPrimaryKey).Assembly
.GetTypes()
Expand Down
15 changes: 3 additions & 12 deletions Benchmarks.App/SpectreLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
6 changes: 3 additions & 3 deletions Benchmarks/GuidPrimaryKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClusteredIndex>());
await dbContext.SaveChangesAsync();
Expand All @@ -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<ClusteredIndex>());
await dbContext.SaveChangesAsync();
Expand All @@ -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<NonClusteredIndex>());
await dbContext.SaveChangesAsync();
Expand Down

0 comments on commit d98a041

Please sign in to comment.