Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jonsequitur
Copy link

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.

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);
Copy link
Owner

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.

Copy link
Author

@jonsequitur jonsequitur Jun 16, 2020

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.

Copy link
Author

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.

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants