Line items to invoice summary
Requirement
An order's line items each have a product, category, quantity, and unit price. Print the invoice summary: one line per category with its total (quantity × unit price, summed), largest category first, then a grand total. The data is in the code below; both versions must print the lines shown under Expected output.
Expected output
Invoice by category: Electronics: $124.87 Office: $75.80 Pantry: $29.50 Total: $230.17
Side by side
Native Dart
FxDart
Why they differ
The same amount, qty * unitPrice, is summed twice — per
category and overall — and the two versions treat that differently.
Native Dart spells it as two unrelated idioms: a mutating
for loop into a map for the categories, then a
fold with an explicit seed for the grand total. FxDart
says "sum of a field" the same way both times — sumBy —
once per groupBy group and once over all items, with
sortBy ranking the rows. When the invoice grows a
discount rule, one vocabulary changes in one place per pipeline; the
native version changes a loop body and a fold.
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 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.