本页尚未翻译,因此以英文显示。 参与翻译

Category with highest average expense

FxDart wins

Requirement

Given a month of expenses — each with a date, category, and amount — find the category with the highest average amount per transaction, and print it with the average formatted to two decimals. The data is in the code below; both versions must print the line shown under Expected output.

Expected output
Highest average spend: Travel ($111.00 per transaction)

Side by side

Native Dart

FxDart

Why they differ

Core Dart has neither groupBy nor maxBy; package:collection supplies both — but as top-level functions, not chain steps. The native version therefore reads inside-out: maxBy(… wrapping a map over entries of a groupBy(… — three idioms (function call, method chain, function call) for one three-step thought. FxDart keeps the reading order equal to the data flow: groupBy the transactions, map each group to (category, average), maxBy the average. Same algorithm, but the sentence runs left to right.

Benchmark

Apple M1 Max, 32 GB RAM · Dart 3.12.2 (AOT-compiled) · 2026-08-24

N = 100

Time Tie

Native Dart 8.4 µs
FxDart 7.9 µs

Peak memory Tie

Native Dart 16.5 MB
FxDart 16.6 MB

N = 10,000

Time Tie

Native Dart 365 µs
FxDart 355 µs

Peak memory Tie

Native Dart 22.9 MB
FxDart 22.9 MB

N = 1,000,000

Time Native wins

Native Dart 60.5 ms
FxDart 64.6 ms

Peak memory Tie

Native Dart 136.9 MB
FxDart 136.1 MB

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.