このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

Leaderboard with tied ranks

FxDart wins

Requirement

Print a leaderboard from six players' scores, highest first, where equal scores share a rank — dense ranking, so two players on 87 points are both #2 and the next score down is #3. The data is in the code below; both versions must print the lines shown under Expected output.

Expected output
#1 Leo — 92 pts
#2 Mina — 87 pts
#2 Anton — 87 pts
#3 Sofia — 75 pts
#3 Kai — 75 pts
#4 Bea — 60 pts

Side by side

Native Dart

FxDart

Why they differ

Tied ranks force the native loop to carry two pieces of mutable state — the current rank and the previous score — and the tie rule lives in an if whose correctness you check by replaying the loop in your head. The FxDart version states the structure instead: sortBy descending, groupBy score (one group per rank), walk the groups with entries + zipWithIndex (group index = rank), and flatMap each group back into player lines. "Equal scores share a rank" stops being emergent loop behavior and becomes the pipeline's shape.

Benchmark

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

N = 100

Time Tie

Native Dart 22 µs
FxDart 26 µs

Peak memory Tie

Native Dart 16.4 MB
FxDart 16.6 MB

N = 10,000

Time Tie

Native Dart 2.41 ms
FxDart 2.37 ms

Peak memory Tie

Native Dart 23.5 MB
FxDart 24.1 MB

N = 1,000,000

Time FxDart wins

Native Dart 533.8 ms
FxDart 470.7 ms

Peak memory Tie

Native Dart 231.5 MB
FxDart 228.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.