Price drops between two snapshots
Requirement
Two snapshots of a shop's price list (data in the code): June and July. Some items got cheaper, some more expensive, one was discontinued and one is new. Report every item that dropped in price — old price, new price, and the drop — sorted by biggest drop first, plus a callout for the single biggest drop and the total savings. Both versions must print the report under Expected output.
Expected output
Price drops, June -> July Hand Grinder $49.90 -> $44.00 (-$5.90) Espresso Beans $18.00 -> $14.50 (-$3.50) Filter Papers $6.40 -> $5.90 (-$0.50) Biggest drop: Hand Grinder (-$5.90) Total savings if bought now: $9.90
Side by side
Native Dart
FxDart
Why they differ
The whole task is one flow: index June by SKU, keep July items that got
cheaper, pair each with its drop, sort by drop. FxDart has a named step
for each move — indexBy for the lookup table,
filter → map → sortBy for the
pipeline, then head and sumBy reuse the same
result list for the summary lines. Native Dart can express it — a map
literal for the index, where/map/
sortedBy for the chain — but the vocabulary is scattered:
fold with a seed instead of sumBy,
sortedBy<num> with a negated key, and no name at all
for "build me a lookup by key".
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time FxDart wins
Peak memory FxDart wins
N = 1,000,000
Time FxDart wins
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.