Average order value over $100
Requirement
From a batch of shop orders, take only those totalling over $100 and print their average value as a currency amount. The data is in the code below; both versions must print the line shown under Expected output.
Expected output
Average large-order value: $203.81
Side by side
Native Dart
FxDart
Why they differ
Honestly: they don't, much — a tie. Core Dart alone would need a
fold-and-count (or a sum divided by a length, walking the data twice),
but package:collection's .average closes that
gap, leaving where → map → average against
filter → averageBy. FxDart saves the intermediate
map by taking the key function directly, and
averageBy is one word instead of an extension property on a
projected iterable — vocabulary, not victory. Both read fine.
Benchmark
N = 100
Time Tie
Peak memory Tie
N = 10,000
Time Tie
Peak memory FxDart wins
N = 1,000,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.