Skip to content

faster version of _nwise #1572

@pkoppstein

Description

@pkoppstein

Here are plug-in replacements for the existing defs. These replacements use 0-arity filters to effect the recursion, and are ridiculously faster even for arrays of size 10^4. (*)

def _nwise($n):
  def nw: if length <= $n then . else .[0:$n] , (.[$n:] | nw) end;
  nw;

def _nwise(a; $n): a | _nwise($n);

(*) [[range(0;n)] | _nwise(3)] | length

            builtin.jq   replacement
n           u+s          u+s
10,000      23.0s        0.027s

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions