Categories over their monthly budget
Requirement
Each spending category has a monthly budget. From July's transactions, total each category, keep only the categories that went over their budget, and print them worst offender first — spent, budget, and the overage on each line. The data is in the code below; both versions must print the lines shown under Expected output.
Expected output
Over budget in July: Food: $135.75 spent, $120.00 budget (over by $15.75) Fun: $34.75 spent, $30.00 budget (over by $4.75) Bills: $90.33 spent, $90.00 budget (over by $0.33)
Side by side
Native Dart
FxDart
Why they differ
The formatting line is identical in both versions — the difference is
everything before it. Native Dart does the grouping by hand in a
mutable map, then switches idiom twice: a for loop to
total, a where to filter, a cascade-sort
with a hand-built comparator to rank. The FxDart version is one
vocabulary end to end: groupBy, map to
totals, filter against the budget, sortBy
the overage, join. Each business rule — over budget,
worst first — is one named step you can point at in a code review.
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time Tie
Peak memory FxDart wins
N = 1,000,000
Time FxDart wins
Peak memory FxDart wins
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.