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

Rank the month by category

FxDart wins

Requirement

Given ledger transactions with a few June stragglers mixed in, keep only July 2026 and rank the top three categories by total spend — biggest first — printing each category with its total and how many purchases it covers. The data is in the code below; both versions must print the lines shown under Expected output.

Expected output
Bills: $108.46 (2 purchases)
Food: $84.40 (4 purchases)
Fun: $37.00 (2 purchases)

Side by side

Native Dart

FxDart

Why they differ

The task is one thought — keep the month, group, total, rank, top three — and the FxDart version is one chain: filter keeps July, groupedBy yields (key:, items:) records, so the per-category total is a map step away, and sortByDesc says "biggest first" by key. Native Dart splits the same thought across a Map: groupListsBy (from package:collection) ends the fluent chain, and descending order means the comparator-operand swap (a, b) => b…compareTo(a…) — a classic silent-bug site, and the reason the FxDart side never negates a key.

Honestly: package:collection covers the grouping well, and for a one-off report the native version is fine. The chain earns its keep as the report grows — every added step (a filter, a second ranking) extends the pipeline instead of another entries round-trip.

Benchmark

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

N = 100

Time Tie

Native Dart 4.5 µs
FxDart 13 µs

Peak memory Tie

Native Dart 16.5 MB
FxDart 16.6 MB

N = 10,000

Time Tie

Native Dart 348 µs
FxDart 299 µs

Peak memory Tie

Native Dart 17.5 MB
FxDart 17.5 MB

N = 1,000,000

Time Tie

Native Dart 33.2 ms
FxDart 32.1 ms

Peak memory Tie

Native Dart 146.9 MB
FxDart 148.0 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.