Esta página ainda não foi traduzida, por isso é exibida em inglês. Ajude a traduzir

Top 5 merchants by total spend

FxDart wins

Requirement

Given a month of ledger transactions — each with a date, merchant, and amount — find the five merchants you spent the most at: group by merchant, total each group, sort the totals descending, and print the top five. The data is in the code below; both versions must print the lines shown under Expected output.

Expected output
Green Grocer: $81.95
Electric Co: $60.34
Noodle Bar: $40.00
Cafe Aroma: $36.50
Book Nook: $27.99

Side by side

Native Dart

FxDart

Why they differ

Core Dart has no grouping at all, so the native version pulls in package:collection — and grouping there ends the chain: groupListsBy hands back a Map, so ranking it means naming an intermediate variable, re-entering through .entries, and reading each group as an untyped kv.key / kv.value pair. Sorting adds two more workarounds: an explicit <num> type argument (inference fails because double is Comparable<num>, not Comparable<double>) and a negated key, since sortedBy only sorts ascending.

In FxDart the four steps are four links of one chain, top to bottom in the order the requirement states them. groupedBy stays inside the pipeline — it yields (key:, items:) groups instead of a map, so nothing has to be unpacked and re-wrapped — and sortByDesc says “descending” in its name instead of encoding it as a minus sign. No intermediate variable, no type-argument ceremony, no sign trick: the code says group, rank, take five.

Benchmark

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

N = 100

Time Tie

Native Dart 25 µs
FxDart 138 µs

Peak memory Tie

Native Dart 17.0 MB
FxDart 17.1 MB

N = 10,000

Time Tie

Native Dart 712 µs
FxDart 588 µs

Peak memory Tie

Native Dart 22.9 MB
FxDart 23.7 MB

N = 1,000,000

Time FxDart wins

Native Dart 116.8 ms
FxDart 63.4 ms

Peak memory FxDart wins

Native Dart 137.3 MB
FxDart 117.8 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.