Running account balance
Requirement
An account opens July with a $250.00 balance and sees six signed transactions — salary in, rent and groceries out. Print one currency line per step: the opening balance first, then the balance after each transaction. The data is in the code below; both versions must print the lines shown under Expected output.
Expected output
Opening balance $250.00 Salary $2850.00 Rent $1700.00 Green Grocer $1656.80 Refund $1685.30 Electric Co $1624.96 Cafe Aroma $1615.16
Side by side
Native Dart
FxDart
Why they differ
Core Dart has fold, which collapses the list to the
final balance — but this task needs every intermediate one, and
there is no scan. So the native version falls back to a
mutable balance variable threaded through a loop, and the
formatting is interleaved with the accumulation. FxDart's
scan yields each accumulated state as a value (the seed
first — which lands the opening-balance line for free), and
map formats afterwards as a separate, swappable step.
Running state as a pipeline stage instead of a mutation is exactly the
vocabulary Dart is missing here.
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time Tie
Peak memory Tie
N = 1,000,000
Time Native 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.