Weekly averages from daily readings
Requirement
A temperature sensor logged one reading per day for three full weeks (21 values). Report the average per 7-day week, one line per week, numbered from 1. The data is in the code below; both versions must print the lines shown under Expected output.
Expected output
Week 1: 21.3°C Week 2: 25.0°C Week 3: 20.5°C
Side by side
Native Dart
FxDart
Why they differ
"Split into groups of 7" has no core-Dart spelling, so the native
version runs a counting loop and carves each week out with
sublist(w * 7, w * 7 + 7) — index arithmetic that the
reader must re-verify, and that breaks if the tail week is short.
FxDart's chunk(7) says the grouping in one word (and
handles a short tail), averageBy replaces the
reduce-then-divide dance, and zipWithIndex brings the week
number into the pipeline instead of borrowing the loop counter.
Benchmark
N = 98
Time Tie
Peak memory Tie
N = 9,996
Time Tie
Peak memory Tie
N = 999,999
Time Tie
Peak memory Native wins
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.