// NOTE: the performance of Sort is not measured by counters. The issues
// of https://cuelang.org/issues/745 were mostly related to poor memory
// management.
-- in.cue --
import "list"

_a: [{name: 1}, {name: 3}, {name: 4}, {name: 5}, {name: 6}, {name: 7}, {name: 8}, {name: 9}, {name: 0}]
_b: [_a, _a, _a, _a, _a, _a, _a, _a, _a, _a]
_c: [_b, _b, _b, _b, _b, _b, _b, _b, _b, _b]

out: list.Sort(list.FlattenN(_c, 4), {x: _, y: _, less: x.name < y.name})

@test(eq, at=out.0, {name: 0})
@test(eq, at=out.899, {name: 9})
-- out/todo.txt --
v2 expanded _b and _c elements into independent copies of the sublists;
v3 uses structure sharing (_b elements: ~(_a), _c elements: ~(_b)).
NOTE: this sharing is tested explicitly in share.txtar.
-- out/eval/stats --
Leaks:  0
Freed:  947
Reused: 42
Allocs: 905
Retain: 0

Unifications: 947
Conjuncts:    948
Disjuncts:    0

NumCloseIDs: 1
