mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Add benchmarks
This commit is contained in:
34
CliFx.Benchmarks/Benchmark.cs
Normal file
34
CliFx.Benchmarks/Benchmark.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using CliFx.Benchmarks.Commands;
|
||||||
|
|
||||||
|
namespace CliFx.Benchmarks
|
||||||
|
{
|
||||||
|
[CoreJob]
|
||||||
|
[RankColumn]
|
||||||
|
public class Benchmark
|
||||||
|
{
|
||||||
|
private static readonly string[] Arguments = { "--str", "hello world", "-i", "13", "-b" };
|
||||||
|
|
||||||
|
[Benchmark(Description = "CliFx", Baseline = true)]
|
||||||
|
public Task<int> ExecuteWithCliFx() => new CliApplication(new[] {typeof(CliFxCommand)}).RunAsync(Arguments);
|
||||||
|
|
||||||
|
[Benchmark(Description = "System.CommandLine")]
|
||||||
|
public Task<int> ExecuteWithSystemCommandLine() => new SystemCommandLineCommand().ExecuteAsync(Arguments);
|
||||||
|
|
||||||
|
[Benchmark(Description = "McMaster.Extensions.CommandLineUtils")]
|
||||||
|
public int ExecuteWithMcMaster() => McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute<McMasterCommand>(Arguments);
|
||||||
|
|
||||||
|
// Skipped because this benchmark freezes after a couple of iterations
|
||||||
|
// Probably wasn't designed to run multiple times in single process execution
|
||||||
|
//[Benchmark(Description = "CommandLineParser")]
|
||||||
|
public void ExecuteWithCommandLineParser()
|
||||||
|
{
|
||||||
|
var parsed = CommandLine.Parser.Default.ParseArguments(Arguments, typeof(CommandLineParserCommand));
|
||||||
|
CommandLine.ParserResultExtensions.WithParsed<CommandLineParserCommand>(parsed, c => c.Execute());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark(Description = "PowerArgs")]
|
||||||
|
public void ExecuteWithPowerArgs() => PowerArgs.Args.InvokeMain<PowerArgsCommand>(Arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
CliFx.Benchmarks/CliFx.Benchmarks.csproj
Normal file
21
CliFx.Benchmarks/CliFx.Benchmarks.csproj
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
|
||||||
|
<PackageReference Include="CommandLineParser" Version="2.5.0" />
|
||||||
|
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.3.4" />
|
||||||
|
<PackageReference Include="PowerArgs" Version="3.6.0" />
|
||||||
|
<PackageReference Include="System.CommandLine.Experimental" Version="0.3.0-alpha.19317.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\CliFx\CliFx.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
21
CliFx.Benchmarks/Commands/CliFxCommand.cs
Normal file
21
CliFx.Benchmarks/Commands/CliFxCommand.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using CliFx.Attributes;
|
||||||
|
using CliFx.Models;
|
||||||
|
|
||||||
|
namespace CliFx.Benchmarks.Commands
|
||||||
|
{
|
||||||
|
[Command]
|
||||||
|
public class CliFxCommand : ICommand
|
||||||
|
{
|
||||||
|
[CommandOption("str", 's')]
|
||||||
|
public string StrOption { get; set; }
|
||||||
|
|
||||||
|
[CommandOption("int", 'i')]
|
||||||
|
public int IntOption { get; set; }
|
||||||
|
|
||||||
|
[CommandOption("bool", 'b')]
|
||||||
|
public bool BoolOption { get; set; }
|
||||||
|
|
||||||
|
public Task ExecuteAsync(CommandContext context) => Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
CliFx.Benchmarks/Commands/CommandLineParserCommand.cs
Normal file
20
CliFx.Benchmarks/Commands/CommandLineParserCommand.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using CommandLine;
|
||||||
|
|
||||||
|
namespace CliFx.Benchmarks.Commands
|
||||||
|
{
|
||||||
|
public class CommandLineParserCommand
|
||||||
|
{
|
||||||
|
[Option('s', "str")]
|
||||||
|
public string StrOption { get; set; }
|
||||||
|
|
||||||
|
[Option('i', "int")]
|
||||||
|
public int IntOption { get; set; }
|
||||||
|
|
||||||
|
[Option('b', "bool")]
|
||||||
|
public bool BoolOption { get; set; }
|
||||||
|
|
||||||
|
public void Execute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
CliFx.Benchmarks/Commands/McMasterCommand.cs
Normal file
18
CliFx.Benchmarks/Commands/McMasterCommand.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using McMaster.Extensions.CommandLineUtils;
|
||||||
|
|
||||||
|
namespace CliFx.Benchmarks.Commands
|
||||||
|
{
|
||||||
|
public class McMasterCommand
|
||||||
|
{
|
||||||
|
[Option("--str|-s")]
|
||||||
|
public string StrOption { get; set; }
|
||||||
|
|
||||||
|
[Option("--int|-i")]
|
||||||
|
public int IntOption { get; set; }
|
||||||
|
|
||||||
|
[Option("--bool|-b")]
|
||||||
|
public bool BoolOption { get; set; }
|
||||||
|
|
||||||
|
public int OnExecute() => 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
CliFx.Benchmarks/Commands/PowerArgsCommand.cs
Normal file
20
CliFx.Benchmarks/Commands/PowerArgsCommand.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using PowerArgs;
|
||||||
|
|
||||||
|
namespace CliFx.Benchmarks.Commands
|
||||||
|
{
|
||||||
|
public class PowerArgsCommand
|
||||||
|
{
|
||||||
|
[ArgShortcut("--str"), ArgShortcut("-s")]
|
||||||
|
public string StrOption { get; set; }
|
||||||
|
|
||||||
|
[ArgShortcut("--int"), ArgShortcut("-i")]
|
||||||
|
public int IntOption { get; set; }
|
||||||
|
|
||||||
|
[ArgShortcut("--bool"), ArgShortcut("-b")]
|
||||||
|
public bool BoolOption { get; set; }
|
||||||
|
|
||||||
|
public void Main()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
CliFx.Benchmarks/Commands/SystemCommandLineCommand.cs
Normal file
34
CliFx.Benchmarks/Commands/SystemCommandLineCommand.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System.CommandLine;
|
||||||
|
using System.CommandLine.Invocation;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CliFx.Benchmarks.Commands
|
||||||
|
{
|
||||||
|
public class SystemCommandLineCommand
|
||||||
|
{
|
||||||
|
public static int ExecuteHandler(string s, int i, bool b) => 0;
|
||||||
|
|
||||||
|
public Task<int> ExecuteAsync(string[] args)
|
||||||
|
{
|
||||||
|
var command = new RootCommand
|
||||||
|
{
|
||||||
|
new Option(new[] {"--str", "-s"})
|
||||||
|
{
|
||||||
|
Argument = new Argument<string>()
|
||||||
|
},
|
||||||
|
new Option(new[] {"--int", "-i"})
|
||||||
|
{
|
||||||
|
Argument = new Argument<int>()
|
||||||
|
},
|
||||||
|
new Option(new[] {"--bool", "-b"})
|
||||||
|
{
|
||||||
|
Argument = new Argument<bool>()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
command.Handler = CommandHandler.Create(typeof(SystemCommandLineCommand).GetMethod(nameof(ExecuteHandler)));
|
||||||
|
|
||||||
|
return command.InvokeAsync(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
CliFx.Benchmarks/Program.cs
Normal file
12
CliFx.Benchmarks/Program.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using BenchmarkDotNet.Configs;
|
||||||
|
using BenchmarkDotNet.Running;
|
||||||
|
|
||||||
|
namespace CliFx.Benchmarks
|
||||||
|
{
|
||||||
|
public static class Program
|
||||||
|
{
|
||||||
|
public static void Main() =>
|
||||||
|
BenchmarkRunner.Run(typeof(Program).Assembly, DefaultConfig.Instance
|
||||||
|
.With(ConfigOptions.DisableOptimizationsValidator));
|
||||||
|
}
|
||||||
|
}
|
||||||
14
CliFx.sln
14
CliFx.sln
@@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
Readme.md = Readme.md
|
Readme.md = Readme.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CliFx.Benchmarks", "CliFx.Benchmarks\CliFx.Benchmarks.csproj", "{8ACD6DC2-D768-4850-9223-5B7C83A78513}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -62,6 +64,18 @@ Global
|
|||||||
{4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x64.Build.0 = Release|Any CPU
|
{4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x86.ActiveCfg = Release|Any CPU
|
{4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x86.Build.0 = Release|Any CPU
|
{4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ To be added with a stable release...
|
|||||||
## Libraries used
|
## Libraries used
|
||||||
|
|
||||||
- [NUnit](https://github.com/nunit/nunit)
|
- [NUnit](https://github.com/nunit/nunit)
|
||||||
- [FluentAssertions](https://github.com/fluentassertions/fluentassertions)
|
|
||||||
- [CliWrap](https://github.com/Tyrrrz/CliWrap)
|
- [CliWrap](https://github.com/Tyrrrz/CliWrap)
|
||||||
|
- [FluentAssertions](https://github.com/fluentassertions/fluentassertions)
|
||||||
|
- [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet)
|
||||||
- [Coverlet](https://github.com/tonerdo/coverlet)
|
- [Coverlet](https://github.com/tonerdo/coverlet)
|
||||||
|
|
||||||
## Donate
|
## Donate
|
||||||
|
|||||||
Reference in New Issue
Block a user