using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Order; using CliFx.Benchmarks.Commands; using CommandLine; namespace CliFx.Benchmarks { [SimpleJob] [RankColumn] [Orderer(SummaryOrderPolicy.FastestToSlowest)] public class Benchmark { private static readonly string[] Arguments = {"--str", "hello world", "-i", "13", "-b"}; [Benchmark(Description = "CliFx", Baseline = true)] public async ValueTask ExecuteWithCliFx() => await new CliApplicationBuilder().AddCommand(typeof(CliFxCommand)).Build().RunAsync(Arguments); [Benchmark(Description = "System.CommandLine")] public async Task ExecuteWithSystemCommandLine() => await new SystemCommandLineCommand().ExecuteAsync(Arguments); [Benchmark(Description = "McMaster.Extensions.CommandLineUtils")] public int ExecuteWithMcMaster() => McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(Arguments); [Benchmark(Description = "CommandLineParser")] public void ExecuteWithCommandLineParser() => new Parser() .ParseArguments(Arguments, typeof(CommandLineParserCommand)) .WithParsed(c => c.Execute()); [Benchmark(Description = "PowerArgs")] public void ExecuteWithPowerArgs() => PowerArgs.Args.InvokeMain(Arguments); [Benchmark(Description = "Clipr")] public void ExecuteWithClipr() => clipr.CliParser.Parse(Arguments).Execute(); [Benchmark(Description = "Cocona")] public void ExecuteWithCocona() => Cocona.CoconaApp.Run(Arguments); } }