-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add program for new version #1
base: master
Are you sure you want to change the base?
Conversation
command-line-api-2/Program.cs
Outdated
command.AddOption(new Option<bool>(new[] { "--bool", "-b" }, "Bool option")); | ||
command.AddOption(new Option<string>(new[] { "--string", "-s" }, "String option")); | ||
|
||
command.Handler = CommandHandler.Create<bool, string>(Run); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is non-realistic. The typical programs have dozens of options. Passing several dozens of options as generic arguments does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We support binding complex classes, so the command option/argument count isn't constrained by the handler method parameter count. It's similar to ASP.NET Core model binding in this regard. I'll update with that approach for a more apples-to-apples comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the PR. Performance between these two iterations is equivalent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command-line-api-3
example I've added takes over object initialization from the model binder, which shaves about 10ms off of the previous project (still included for comparison). This API could also use a small improvement so that the lookup isn't name based, which is already supported in other APIs.
The adds a new comparison project (command-line-api-2) which incudes a change to the program logic which will exclude the default middleware, and uses an updated version of System.CommandLine with reduced usage of LINQ in the tokenizer. It removes about 25ms on average from the execution time.
Most of the performance gains to be made by optimizing System.CommandLine are in the binding, not the parsing, but this change was very quick to make.