Fastest and slowest request
Requirement
A health check probes eight endpoints through an async
measure call and reports the fastest and the slowest
latency in milliseconds. The fixed samples are in the code; both
versions must print the two lines shown under
Expected output.
Expected output
fastest: 12 ms slowest: 210 ms
Side by side
RxDart
FxDart
Why they differ
Reductions are where push and pull converge: to know the extreme you
must see the whole sequence, so both min and
max are terminal and both return a Future.
RxDart's versions also accept an optional comparator for elements
that aren't Comparable; FxDart keeps min
and max as numeric terminals and covers keyed cases with
minBy/maxBy. On plain integers the two
calls are word-for-word identical — the FxDart side just lifts the
pulls into an async chain with toAsync first.
The mirrored wrinkle is that each reduction consumes the
source. A Dart stream is single-subscription, so asking for min and
then max means two subscriptions — hence the latencies()
factory on the RxDart side. The FxDart side has the same shape for
the same reason: a terminal call drains the chain, so the second
reduction pulls a fresh one. Both therefore measure twice (collecting
into a list first is the shared alternative), and neither model has
an edge worth claiming: a tie, decided by which way the surrounding
code already flows.
Benchmark
Async case: the headline scale is N = 10,000, not 1,000,000. Every element costs an event-loop turn on both sides, so a million real awaits would measure Dart's event loop for minutes — not the pipeline. Delays are zero-length and the example's concurrency limit is kept; what the bars compare is the pipeline machinery.
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time FxDart 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.