Revisits the comparison from the closed #125 (gabteles), fixing the
reversed Set#subset? arguments so every approach returns the same
result (guarded by an equivalence check), and benchmarks across modern
Ruby versions.
Findings:
- (a1 - a2).empty? is the consistent winner for true-subset inputs.
- a1.all? { include? } only wins when a1 is NOT a subset (short-circuits)
and is O(n*m) on large true subsets.
- Set#subset? (incl. to_set) went from ~6.8x slower on 3.3/3.4 to ~1.7x
slower on 4.0, where Set got much faster.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Adds an Array benchmark for subset checks (is every element of a1 also in a2?), comparing five approaches across Ruby 3.3.10, 3.4.7, and 4.0.0:
Background
This revisits the comparison from #125 by @gabteles (now closed). That PR had two problems the reviewers (@mblumtritt, @Arcovion) hinted at back in 2017:
This version fixes the Set arguments, adds an equivalence guard so all five approaches must agree before the benchmark runs, and reports results across three modern Ruby versions.
Findings
Notes
🤖 Generated with Claude Code