-
-
Notifications
You must be signed in to change notification settings - Fork 376
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 possibility to disable intermediate shell #336
Comments
Hyperfine could detect such simple commands automatically, without introducing an explicit command line option to disable the shell. |
I'm not sure how that would work: hyperfine "foo" Is hyperfine 'foo "$HOME"' What would we do in this case? Certainly looks like a normal command that is called with a single argument. Does the user want that variable to be expanded or not? If it should be expanded, we need a shell. And then for actual, obvious shell commands:
.. how would we detect that we need a shell for those? We would need to know lots of shell syntax to determine that. |
My basic idea is to define a limited POSIX shell subset: single command, no (unescaped) shell meta-characters with some exceptions like This way, we don't introduce new syntax. So, no new options, and no subtle differences between an actual shell and our one. Just some commands run faster and are measured more accurately than the others.
It isn't a shell function since there are no predefined functions or aliases in a fresh shell (check it with Also, a cautious option:
We should not change semantics here, so yes. We should run an actual shell here if we do not want to handle variable expansion. If the user doesn't want it to be expanded, they should escape it as in the shell:
Unquoted metacharacters used here, so we need a shell here. We may refer to the POSIX shell standard and
Well, yes… Maybe this should be in a separate crate. Or maybe it is already implemented in some crate since it sounds like a common task? |
Shameless plug: I did a similar task for my own project, so I am somewhat familiar with parsing shell syntax as I did some research: But in my case, it was sufficient to detect a single-word command (e.g. |
@xzfc although it is technically possible to define and implement a subset of Imagine one would try to benchmark two sets of commands, and for some reason one of them "tricks" our parser into using However I would have a different proposal:
Some observations:
Another alternative, given that
The advantage of this second proposal is that one can now easily compose commands as such:
As seen it can handle both single variables, but also arrays. The syntax is a little-bit more convoluted as it implies handling single quotes, but it's not extremely complex, as I think it's only this:
|
That is pretty much what I suggested in the first post, I believe. This is what |
OK, so I thought "working code is better than no code", therefore I've made a small patch. Basically if one sets If it's acceptable I can make a pull request. |
That would be great. I haven't looked into your code in detail, but it shouldn't be hard to change from |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as off-topic.
This comment was marked as off-topic.
@Pietruszek I haven't made the pull request yet, however you are welcome to try the patched variant available at: https://github.com/cipriancraciun/hyperfine/tree/feature-336 In order to trigger the behaviour, use as shell the empty string, i.e. Regarding the patch, although I've tested it myself locally, with and without the intermediary shell, I don't think it makes a much difference, mainly because the current code is capable of detecting the shell overhead. |
@cipriancraciun I tried compiling your version on my Windows machine with It's a function marked with |
@cipriancraciun Would you like to open a PR with your changes? I would love to get this integrated into Before we integrate this, I would propose we talk about the CLI to support this. I don't think |
This comment was marked as off-topic.
This comment was marked as off-topic.
@Pietruszek @sharkdp Sorry for the extreemly late reply. See pull request #429. I couldn't |
@Pietruszek as described #429, it should now compile on Windows. If you have the time, please test. |
This has now been implemented in #487. Thanks everyone! Especially @cipriancraciun for the initial implementation. |
It would be great to have a way to disable the intermediate shell for very fast commands where we need a resolution that is better than 3 ms (typical standard deviation of the shell spawning time).
This new mode would obviously not be able to benchmark complex commands like
seq 1000 | factor
, but we could usehttps://crates.io/crates/shellwordshttps://crates.io/crates/shell-words to be able to run commands likemy_command --foo "some strong" --bar
.The text was updated successfully, but these errors were encountered: