Rank the month by category
Requirement
Given ledger transactions with a few June stragglers mixed in, keep only July 2026 and rank the top three categories by total spend — biggest first — printing each category with its total and how many purchases it covers. The data is in the code below; both versions must print the lines shown under Expected output.
Expected output
Bills: $108.46 (2 purchases) Food: $84.40 (4 purchases) Fun: $37.00 (2 purchases)
Side by side
Native Dart
FxDart
Why they differ
The task is one thought — keep the month, group, total, rank, top
three — and the FxDart version is one chain: filter keeps
July, groupedBy yields
(key:, items:) records, so the per-category total is a
map step away, and sortByDesc says
"biggest first" by key. Native Dart splits the same thought across a
Map: groupListsBy (from
package:collection) ends the fluent chain, and descending
order means the comparator-operand swap
(a, b) => b…compareTo(a…) — a classic
silent-bug site, and the reason the FxDart side never negates a key.
Honestly: package:collection covers the grouping well, and
for a one-off report the native version is fine. The chain earns its
keep as the report grows — every added step (a filter, a second
ranking) extends the pipeline instead of another entries
round-trip.
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time Tie
Peak memory Tie
N = 1,000,000
Time Tie
Peak memory Tie
Bars are medians of repeated timed iterations in fresh processes per side (small N is batched for timer resolution). Sides within 5% of each other — or within 0.6 ms, a difference no person can perceive — count as a tie; close relative races are re-measured up to 5 runs. In an app, anything under a few milliseconds is invisible to the user regardless of which bar is shorter. Memory is peak process RSS. The Dart VM and the dataset are identical on both sides, so the difference between the two bars is what the pipeline itself holds onto.