Comments (4)
Yeah, defining range/2 by jq-coded (#1960) was rejected previously due to an objection about performance and type validation.
from jq.
(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"]
range($A; $B; $C)
is literally equivalent to ($A | while(. < $B; . + $C))
. ^^
$ jq -cn '[] | while(. < ["a","a","a","a"]; . + ["a"])'
[]
["a"]
["a","a"]
["a","a","a"]
from jq.
Had a deeper look at this. TIL range/2
is implemented as op code block literal in C
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'
from jq.
@itchyny Ah i see, thanks for referencing your PR.
Wonder how much work it would be to make the current range/2
in C take a step arg and then use that for range/1
/range/2
and that way fix the arg type inconsistency between them?
from jq.
Related Issues (20)
- Multiplying -1 with 0 must result 0, not -0 HOT 2
- ~/.jq is not sourced on windows
- Unexpected output HOT 1
- Null bytes are handled inconsistently HOT 5
- tonumber doesn't work on `true` or `false` HOT 4
- "color for object keys" from JQ_COLORS doesn't seem to be respected HOT 4
- Regular expression alternation (|) used with quantifier (* or +) returns inconsistent results when first alternative is able to match an empty string HOT 3
- Create Multi Smaller Files From a Big Json File HOT 5
- Add the Symbolic Binding Operator ("as") to the operator priority table HOT 1
- Including and importing module with importing JSON crashes jq
- The code example for trim ltrim and rtrim from the manual do not work HOT 2
- Incorrect `Invalid path expression` in destructuring expressions
- 1.7.1 dumps core on Cygwin, trying to find the input filename to print an error message HOT 5
- jq --raw modes, --binary and newlines
- Request for snap maintenance HOT 11
- strptime month does not match input HOT 2
- Using unique or unique_by in a filter causes subsequent (after comma ,) filter inputs to be replaced with its output HOT 5
- Docker images lack `latest` tag HOT 2
- modulemeta failure when module location is found by "search"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jq.