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

Allow passing data to stdin #541

Closed
Self-Perfection opened this issue Aug 17, 2022 · 4 comments · Fixed by #563
Closed

Allow passing data to stdin #541

Self-Perfection opened this issue Aug 17, 2022 · 4 comments · Fixed by #563
Labels

Comments

@Self-Perfection
Copy link

I would like to compare performance of http://kmkeen.com/jshon/ and https://github.com/jsqry/jsqry-cli2

Both are really fast so hyperfine suggests running with --shell=none for accurate results.

But the latter tool can only process data from stdin therefore I have to call it via shell to provide fixed stdin input like 'jsqry < sample1'. And therefore I cannot reliably measure its performance.

I suggest new parameter to hyperfine --stdin-data=FILEPATH which should open given file as stdin before forking to measured process. This parameter would obviate the need for shell in my test.

@InCogNiTo124
Copy link

InCogNiTo124 commented Aug 22, 2022

I have exactly the same request. I guess the issue is the heterogenity of input passing - some commands read only stdin, some have a --file flag, etc. How to specify which command you wish to redirect the stdin?

@sharkdp
Copy link
Owner

sharkdp commented Aug 23, 2022

Having a --stdin-data (or maybe --input to completement --output) argument in hyperfine sounds reasonable. However, I would first like to understand this use case a bit better.

Both are really fast so hyperfine suggests running with --shell=none for accurate results.

hyperfine suggests this if the commands in question are faster than 5 ms. The reason for this is that a typical shell spawning time is on the order of a few milliseconds. We subtract this shell spawning time from the actual time, but the error being introduced by this procedure is likely to be on a similar order of magnitude.

It is true that using --shell=none will produce more accurate results, as we get rid of this shell spawning (and compensation) procedure. However, please note that most programs themselves also have a startup time of of a few milliseconds. If you (presumably) want to benchmark JSON parsing speed and you see program runtimes smaller than 5 ms, I'm afraid your input is too small.

@Self-Perfection
Copy link
Author

In this case I would like to compare startup times of these apps, so I have made input is made as small as possible deliberately. Venerable jq got too bloated to start, around 30 ms. So I wanted to compare it with competitors.

@zhuzhzh
Copy link

zhuzhzh commented Aug 28, 2022

I want to compare 'ug ' and 'rg keyword'. but ugrep will exit with non-0. I guess ugrep will check if it's stdin. so --stdin-data is needed.

sharkdp pushed a commit that referenced this issue Mar 15, 2023
This argument accepts a path to a file. The data contained in the file will be passed to the command via stdin.

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

Successfully merging a pull request may close this issue.

4 participants