Compound interest table
Requirement
Print a year-by-year balance table for $1000 at 5% compound interest over six years — one line per year, starting from the year-0 opening balance, each amount formatted to two decimals. The constants are in the code below; both versions must print the lines shown under Expected output.
Expected output
year 0: $1000.00 year 1: $1050.00 year 2: $1102.50 year 3: $1157.63 year 4: $1215.51 year 5: $1276.28 year 6: $1340.10
Side by side
Native Dart
FxDart
Why they differ
A running balance is a running fold, and core Dart has no word
for it: fold gives only the final value, so the native
version falls back to a loop that seeds a list with the year-0 line,
mutates balance, and appends — the compounding rule, the
iteration, and the formatting all share one body. FxDart's
scan turns each intermediate balance into a value in the
pipeline: the seed is the year-0 row, the compounding rule is one pure
function, and formatting is a separate map step. Want the
year the balance first passes $1200? Chain a filter — the loop version
has to grow another flag instead.
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.