Skip to content

expr: Get rid of clap for performance reasons #7352

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

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

RenjiSann
Copy link
Collaborator

As a side effect, we also now have the right behavior when adding arguments after --help or --version. Before this change, clap would have printed the help, but it is expected that flags are ignored if argc > 2 (more than 1 arg is given)

Benchmarks:

$ export N=2500

# Before
$ hyperfine -m 1000 -- "./expr_clap $(yes 1 | head -n $N | paste -s - 2>&1 | sed 's/\t/ + /g')"
  Time (mean ± σ):      47.4 ms ±   3.3 ms    [User: 34.4 ms, System: 12.8 ms]
  Range (min … max):    37.3 ms …  74.4 ms    1000 runs

#After
$ hyperfine -m 1000 -- "./expr_no_clap $(yes 1 | head -n $N | paste -s - 2>&1 | sed 's/\t/ + /g')"
  Time (mean ± σ):      24.7 ms ±   2.2 ms    [User: 13.9 ms, System: 10.7 ms]
  Range (min … max):    18.8 ms …  34.7 ms    1000 runs

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Here's a small suggestion

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@RenjiSann
Copy link
Collaborator Author

by running the GNU tests manually, I realized that I forgot to handle -- which can appear in the command. I made the necessary changes (diff)

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

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.

3 participants