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

Longest streak of no-spend days

FxDart wins

Requirement

From one month of ledger transactions, find the longest streak of consecutive July days with no spending at all (July 2026 has 31 days). Print a calendar strip marking each no-spend day with #, then the streak length. The data is in the code below; both versions must print the lines shown under Expected output.

Expected output
July (# = no-spend day): ···###··######··#####·#####··##
Longest no-spend streak: 6 days

Side by side

Native Dart

FxDart

Why they differ

A streak is a running value, and that is scan's exact job: fold's every intermediate state, kept. The pipeline reads as the definition — the days (range), mapped to spent-or-not, scanned into a running streak that resets on a spend day, and max picks the peak. The native loop computes the same thing with two mutable counters and an if — you verify it by mentally replaying iterations, and the streak logic is fused to the strip-building beside it. In the FxDart version the strip (map + join) and the streak are two independent, separately readable pipelines over the same range.

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 5.6 µs

Peak memory Tie

Native Dart 16.4 MB
FxDart 16.5 MB

N = 10,000

Time Tie

Native Dart 261 µs
FxDart 262 µs

Peak memory Tie

Native Dart 19.6 MB
FxDart 19.6 MB

N = 1,000,000

Time Tie

Native Dart 23.8 ms
FxDart 24.0 ms

Peak memory Tie

Native Dart 106.6 MB
FxDart 106.4 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.