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

Align forecast with actuals

Toss-up

Requirement

A five-day temperature forecast sits next to what the sensor actually measured. Pair the two series position by position and print one line per day: forecast, actual, and the signed difference to one decimal place. The data is in the code; both versions must print the lines shown under Expected output.

Expected output
day 1: 21.0 forecast vs 20.6 actual (-0.4)
day 2: 22.5 forecast vs 23.1 actual (+0.6)
day 3: 23.0 forecast vs 23.0 actual (+0.0)
day 4: 24.5 forecast vs 25.2 actual (+0.7)
day 5: 22.0 forecast vs 21.4 actual (-0.6)

Side by side

RxDart

FxDart

Why they differ

Positional pairing is symmetric across the models and both libraries ship it: zipWith combines the n-th event of one stream with the n-th of another, zip pairs the n-th pulls of two iterables. Both stop at the shorter side, both keep order by construction. The formatting function is shared verbatim, so the panels differ only in how the two series are lifted into a pipeline.

The models do hide different machinery under the shared name. Stream zipWith is a small coordination engine: two live subscriptions, a one-slot buffer for whichever side is ahead, and pause/resume to keep a fast producer from outrunning a slow one. Iterable zip is two iterators advanced in lockstep — the consumer's pull is the synchronisation, so there is nothing to buffer and no one to pause. For two fixed lists none of that machinery is ever exercised, which is exactly why this one is a tie: pick the version that matches where your series actually live.

Benchmark

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

N = 100

Time Tie

RxDart 88 µs
FxDart 46 µs

Peak memory Tie

RxDart 16.6 MB
FxDart 16.4 MB

N = 1,000,000

Time FxDart wins

RxDart 799.0 ms
FxDart 461.3 ms

Peak memory Tie

RxDart 206.6 MB
FxDart 215.4 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.