-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
range/3
behaviour when $init and $upto arguments are not numbers
#3116
Comments
(Repost from discord: I didn't notice there was an issue for this) $ jq -cn 'range([];["a","a","a","a"];["a"])'
[]
["a"]
["a","a"]
["a","a","a"]
$ jq -cn '[] | while(. < ["a","a","a","a"]; . + ["a"])'
[]
["a"]
["a","a"]
["a","a","a"] |
Had a deeper look at this. TIL Lines 1858 to 1873 in c127616
RANGE op code Lines 515 to 545 in c127616
and implementing it in pure jq would probably have quite a performance degradation: # range/2 (uses RANGE opcode)
# vs
# range/3 (uses while function written in jq)
$ hyperfine "jq -n 'range(5000000) | empty'" "jq -n 'range(0;5000000;1) | empty'"
Benchmark 1: jq -n 'range(5000000) | empty'
Time (mean ± σ): 543.0 ms ± 8.0 ms [User: 537.1 ms, System: 1.0 ms]
Range (min … max): 532.0 ms … 557.7 ms 10 runs
Benchmark 2: jq -n 'range(0;5000000;1) | empty'
Time (mean ± σ): 2.005 s ± 0.017 s [User: 1.993 s, System: 0.002 s]
Range (min … max): 1.974 s … 2.039 s 10 runs
Summary
jq -n 'range(5000000) | empty' ran
3.69 ± 0.06 times faster than jq -n 'range(0;5000000;1) | empty' |
Yeah, defining range/2 by jq-coded (#1960) was rejected previously due to an objection about performance and type validation. |
@itchyny Ah i see, thanks for referencing your PR. Wonder how much work it would be to make the current |
range(0;[];1)
keeps outputting increasingly forever (also with{}
because how<
work i guess)range([];0;1)
outputs nothing.gojq errors for both, jaq behave the same as jq it seems. Think i would expect it to thrown some kind of error on non-number arguments, same as
range/1
andrange/2
do already.The text was updated successfully, but these errors were encountered: