Three consecutive readings over the limit
Requirement
Hourly CO2 readings for one day. Flag every window of three consecutive readings all above 1000 ppm — that means the ventilation could not catch up for three straight hours — and print each window as a start–end hour range under a header line. The data is in the code below; both versions must print the lines shown under Expected output.
Expected output
Ventilation alerts (3h over 1000 ppm): 11:00–13:00 15:00–17:00
Side by side
Native Dart
FxDart
Why they differ
Core Dart has no sliding window, so the native version is an index
loop with an i + 2 < length bound and three manual
lookups — correct, but every piece of it is bookkeeping a reader must
check. The FxDart version builds the window as data:
zip3 the list with itself shifted by one and by two
(drop(1), drop(2)), and each element becomes
a (reading, next, next-next) triple — no indices anywhere.
zip3 stopping at the shortest input is exactly the
window-fits-entirely rule the loop encodes as its bound. Widening the
window to 4 hours is one more shifted input, not a re-audit of the
arithmetic.
The shifted inputs are not copies. drop(n) over a
List is a range of that list, and
zip3 reads all three ranges by index — so the pipeline
walks the readings once and allocates one triple per window, which is
why its bar sits close to the loop rather than at a multiple of it.
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time Tie
Peak memory Native wins
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.