本页尚未翻译,因此以英文显示。 参与翻译

Running account balance

FxDart wins

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

Apple M1 Max, 32 GB RAM · Dart 3.12.2 (AOT-compiled) · 2026-08-24

N = 100

Time Tie

Native Dart 24 µs
FxDart 22 µs

Peak memory Tie

Native Dart 16.5 MB
FxDart 16.5 MB

N = 10,000

Time Tie

Native Dart 2.07 ms
FxDart 2.11 ms

Peak memory Tie

Native Dart 24.0 MB
FxDart 23.6 MB

N = 1,000,000

Time Native wins

Native Dart 237.8 ms
FxDart 275.1 ms

Peak memory Tie

Native Dart 182.9 MB
FxDart 185.2 MB

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.