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

Make INDEX/2 more efficient #1654

Closed
wants to merge 1 commit into from

Conversation

EugenGez
Copy link

Hi,

I think there is some faster (a little bit) and more readable implementation of SQL-ish INDEX(...).

About 10% performance win:

~/.jq

# better implementation?
def INDEX2(stream; idx_expr):
  reduce stream as $row ({}; .[($row|idx_expr|tostring)] |= $row);
def INDEX2(idx_expr): INDEX2(.[]; idx_expr);
$ ./jq-index.sh
+ jq -n '[ range(1024*2000) | {id: . } ] | INDEX(.id)  | empty'

real    0m21.124s
user    0m0.000s
sys     0m0.015s
+ jq -n '[ range(1024*2000) | {id: . } ] | INDEX2(.id) | empty'

real    0m19.165s
user    0m0.000s
sys     0m0.015s

Thank You for the great job!

Regards

@coveralls
Copy link

coveralls commented Apr 19, 2018

Coverage Status

Coverage remained the same at 84.615% when pulling bdcb753 on EugenGez:sql-ish-operators into 7fd9e86 on stedolan:master.

@EugenGez EugenGez changed the title Make Make INDEX/2 more efficient Make INDEX/2 more efficient Apr 24, 2018
@itchyny
Copy link
Contributor

itchyny commented Jun 25, 2023

This improvement was included by #1845 (76e72a3) on Feb 27, 2019. Thank you.

@itchyny itchyny closed this Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants