sharkdp / hyperfine

A command-line benchmarking tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trouble with syntax and ripgrep (in fish shell)

ashprice opened this issue · comments

Apologies if there is a better place to ask this; I am unsure yet if it is an bug or a question.

Consider the following sets of commands:

hyperfine 'echo $uuids | tr \' \' \'\n\' | sd \'^([a-f0-9])\' \'^.*foo:"fum".*$1\''

hyperfine 'echo $uuids | tr \' \' \'\n\' | rg \'^\' -r \'foofum\''

These work as expected. (Even if the quoting syntax is horrible.) But if I try to introduce either a capture group, a character group, or a string that will not be matched, I receive an error from hyperfine:

hyperfine 'echo $uuids | tr \' \' \'\n\' | rg \'^([a-f0-9])\' -r \'^.*foo:"fum".*$1\''

hyperfine 'echo $uuids | tr \' \' \'\n\' | rg \'^[a-f0-9]\''

hyperfine 'echo $uuids | tr \' \' \'\n\' | rg \'^a\''

all give:

Error: Command terminated with non-zero exit code: 1. Use the '-i'/'--ignore-failure' option if you want to ignore this. Alternatively, use the '--show-output' option to debug what went wrong.

Using --show-output doesn't give me anything illuminating, sometimes it gives a lot of blank whitespace, but I can't reproduce it now.

Normally, ripgrep would print output for each of the former commands, and fish would display the exit status for the failed match. I would understand it in the case of no match - this should present exist status 1 - but I am not sure what's going on with the cases that do have matches:

$ echo $uuids | tr ' ' '\n' | rg '^[a-f0-9]'
0008bd69-bbb4-4cb6-864a-b542de481cb8
001a9abf-f287-4c9d-8cea-6ae5af09fb1a
0064d167-3669-4579-9794-57632cbf25ae 
... 
$ hyperfine 'echo $uuids | tr \' \' \'\n\' | rg \'^[a-f0-9]\''
Benchmark 1: echo $uuids | tr ' ' '\n' | rg '^[a-f0-9]'
Error: Command terminated with non-zero exit code: 1. Use the '-i'/'--ignore-failure' option if you want to ignore this. Alternatively, use the '--show-output' option to debug what went wrong.
$ hyperfine -i --show-output 'echo $uuids | tr \' \' \'\n\' | rg \'^[a-f0-9]\''
Benchmark 1: echo $uuids | tr ' ' '\n' | rg '^[a-f0-9]'
  Time (mean ± σ):       2.6 ms ±   0.2 ms    [User: 2.1 ms, System: 1.6 ms]
  Range (min … max):     2.2 ms …   3.6 ms    617 runs

  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not
calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.
  Warning: Ignoring non-zero exit code.

I've discovered that turning the shell of with -N leads to some benchmarking proceeding without error. However, it looks to me like it is just echoing the entire string (which makes sense, I guess):

$ hyperfine --show-output -N 'echo $uuids | tr \' \' \'\n\' | rg \'^[a-f0-9]\''
$uuids | tr   \n | rg ^[a-f0-9]
$uuids | tr   \n | rg ^[a-f0-9]
$uuids | tr   \n | rg ^[a-f0-9]
$uuids | tr   \n | rg ^[a-f0-9]
$uuids | tr   \n | rg ^[a-f0-9]
$uuids | tr   \n | rg ^[a-f0-9]
$uuids | tr   \n | rg ^[a-f0-9]
$uuids | tr   \n | rg ^[a-f0-9]
$uuids | tr   \n | rg ^[a-f0-9]
...

I'd be grateful for any help on this, and please let me know if there's any other info I can provide.

(The actual commands I want to test will take somewhat longer than 5ms.)

OK, nevermind and sorry for the traffic - I realized --show-output does what it says on the tin, and that none of the searches were running on anything, because I was borking the syntax for calling the variable in fish - $uuids was evaluating as an empty variable.

Glad you figured it out 👍