このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

Stock level after each move

Toss-up

Requirement

A warehouse ledger for one SKU lists signed moves — positive receipts, negative shipments — starting from an opening stock of 20. Print the opening level, then each move with the level after it, flagging any negative level as a backorder. The moves are in the code; both versions must print the lines shown under Expected output.

Expected output
start: 20
+40: 60
-25: 35
-50: -15 (backorder)
+30: 15
-20: -5 (backorder)
-10: -15 (backorder)
+45: 30

Side by side

RxDart

FxDart

Why they differ

Running state is scan in both dialects — FxDart's is the FxTS port of the same Rx idea, so the fold itself is identical: an accumulator record carrying the move's label and the level after it. The one visible seam is the seed. FxDart's scan emits the seed as its first value, so the opening start: 20 line falls out of the chain for free. RxDart's scan starts emitting at the first fold, so the opening level has to be replayed with startWith — one extra operator, not a hardship.

Past the seed, the two pipelines are the same three words, and the flagging map reads equally well on either side — the pull version merely stays synchronous because the ledger is already in memory, while the stream version awaits its own delivery. Running state over an ordered sequence is home turf for both models: a tie, with the seed-emission difference as the only trivia worth remembering when porting between them.

Benchmark

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

N = 100

Time Tie

RxDart 335 µs
FxDart 12 µs

Peak memory RxDart wins

RxDart 15.1 MB
FxDart 16.5 MB

N = 1,000,000

Time FxDart wins

RxDart 3288.1 ms
FxDart 162.5 ms

Peak memory Tie

RxDart 126.5 MB
FxDart 126.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.