Refunds vs charges, both formatted
Requirement
A ledger mixes charges and refunds (negative amounts). Split it into the
two groups, format every transaction as
merchant $amount, and print one line per group —
refunds first. The data is in the code below; both versions must print
the lines shown under Expected output.
Expected output
refunds: Web Store $89.99, Airline $120.00, Book Nook $27.99 charges: Cafe Aroma $12.50, Web Store $89.99, Noodle Bar $18.90, Airline $240.00, Green Grocer $43.20
Side by side
Native Dart
FxDart
Why they differ
Dart has no partition — when you need both halves,
where only gives you one, so the native version filters
twice: once with the predicate, once with its negation, written out by
hand (< 0 and >= 0). That is two passes
over the data and two predicates to keep in sync — if the refund rule
ever changes, nothing forces the second line to follow. FxDart's
partition makes the split one declaration: a single
predicate, a single pass, and a record destructure that names both
halves. The map + join formatting afterwards
is the same in both.
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time Tie
Peak memory Tie
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.