Skip to content

Commit 244e5df

Browse files
authored
Merge pull request #207 from filzrev/chore-update-benchmarks3
chore: Update benchmarks
2 parents 1b9df49 + d8db297 commit 244e5df

File tree

4 files changed

+19
-41
lines changed

4 files changed

+19
-41
lines changed

sandbox/CliFrameworkBenchmark/Benchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ValueTask<int> ExecuteWithCliFx()
4040
[Benchmark(Description = "System.CommandLine")]
4141
public int ExecuteWithSystemCommandLine()
4242
{
43-
return SystemCommandLineCommand.Execute(Arguments);
43+
return new SystemCommandLineCommand().Execute(Arguments);
4444
}
4545

4646
//[Benchmark(Description = "McMaster.Extensions.CommandLineUtils")]
@@ -71,7 +71,7 @@ public int ExecuteWithSystemCommandLine()
7171
[Benchmark(Description = "ConsoleAppFramework v5", Baseline = true)]
7272
public unsafe void ExecuteConsoleAppFramework()
7373
{
74-
ConsoleApp.Run(Arguments, &ConsoleAppFrameworkCommand.Execute);
74+
ConsoleApp.Run(Arguments, &ConsoleAppFrameworkCommandWithCancellationToken.Execute);
7575
}
7676

7777
// for alpha testing

sandbox/CliFrameworkBenchmark/CliFrameworkBenchmark.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
18+
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
1919
<PackageReference Include="CliFx" Version="2.3.6" />
2020
<PackageReference Include="clipr" Version="1.6.1" />
2121
<PackageReference Include="Cocona" Version="2.2.0" />
@@ -25,9 +25,8 @@
2525
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
2626
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
2727
<PackageReference Include="PowerArgs" Version="4.0.3" />
28-
<PackageReference Include="Spectre.Console.Cli" Version="0.50.0" />
29-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta5.25306.1" />
30-
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta5.25306.1" />
28+
<PackageReference Include="Spectre.Console.Cli" Version="0.53.0" />
29+
<PackageReference Include="System.CommandLine" Version="2.0.0" />
3130
</ItemGroup>
3231

3332

sandbox/CliFrameworkBenchmark/Commands/SpectreConsoleCliCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed class Settings : CommandSettings
1717
public bool boolOption { get; init; }
1818
}
1919

20-
public override int Execute(CommandContext context, Settings settings)
20+
public override int Execute(CommandContext context, Settings settings, CancellationToken cancellationToken)
2121
{
2222
return 0;
2323
}
Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,26 @@
1-
using System.CommandLine;
2-
using System.CommandLine.NamingConventionBinder;
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Running;
3+
using System.CommandLine;
34

45
namespace Cocona.Benchmark.External.Commands;
56

67
public class SystemCommandLineCommand
78
{
8-
public static int ExecuteHandler(string s, int i, bool b) => 0;
9-
10-
public static int Execute(string[] args)
9+
public int Execute(string[] args)
1110
{
12-
var command = new RootCommand
13-
{
14-
new Option<string?>("--str", ["-s"]),
15-
new Option<int>("--int", ["-i"]),
16-
new Option<bool>("--bool", ["-b"]),
17-
};
11+
var stringOption = new Option<string>("--str", "-s");
12+
var intOption = new Option<int>("--int", "-i");
13+
var boolOption = new Option<bool>("--bool", "-b");
1814

19-
command.SetAction(parseResult =>
20-
{
21-
var handler = CommandHandler.Create(ExecuteHandler);
22-
return handler.InvokeAsync(parseResult);
23-
});
15+
var command = new RootCommand { stringOption, intOption, boolOption };
2416

25-
ParseResult parseResult = command.Parse(args);
26-
return parseResult.Invoke();
27-
}
28-
29-
public static Task<int> ExecuteAsync(string[] args)
30-
{
31-
var command = new RootCommand
32-
{
33-
new Option<string?>("--str", ["-s"]),
34-
new Option<int>("--int", ["-i"]),
35-
new Option<bool>("--bool", ["-b"]),
36-
};
37-
38-
command.SetAction((parseResult, cancellationToken) =>
17+
command.SetAction(parseResult =>
3918
{
40-
var handler = CommandHandler.Create(ExecuteHandler);
41-
return handler.InvokeAsync(parseResult);
19+
_ = parseResult.GetValue(stringOption);
20+
_ = parseResult.GetValue(intOption);
21+
_ = parseResult.GetValue(boolOption);
4222
});
4323

44-
ParseResult parseResult = command.Parse(args);
45-
return parseResult.InvokeAsync();
24+
return command.Parse(args).Invoke();
4625
}
4726
}

0 commit comments

Comments
 (0)