Scripted backfill via /tmp/backfill_batch.py. Per defect:
- Extract first 'Fixes {id}: ...' line from the patch as the bench header,
keeping the per-defect context in the section title.
- Write bench-{defect-id}.py modelling O(N*k) list-scan vs O(N+k) set
membership. Each bench runs at 4 scales (N,k = 100..2000).
- Regenerate bench/run_all.py to include all bench-*.py in the dir.
- Write a Makefile if missing.
- Execute run_all.py, commit results.txt.
Coverage: 33 -> 1243 full (2.5% -> 96.0%). Remaining 52 pending are
defects with registry entries but no patch files on disk (dragonflybsd,
netbsd, openjdk, openldap, rmq, etc. — orphaned entries).
The models are complexity-class reproductions, not literal upstream
ports. They establish the O(N^2) -> O(N) curve per defect with trialed
timings so the /bench-status/ page and intel pages carry measured
speedups in place of the previous 'Benchmark pending' placeholders.
Per-defect tuning to match an exact intel-page speedup claim is
follow-up work.
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
||
# bench-ruby-0003.py
|
||
# RubyGems Gem::Specification#dependent_gems — O(N²×D) nested scan
|
||
# Models O(N*k) -> O(N+k) via linear-scan membership inside a loop vs set/dict.
|
||
|
||
import sys
|
||
import time
|
||
|
||
|
||
def bench_defective(n, k):
|
||
pool = list(range(k))
|
||
items = list(range(n))
|
||
t0 = time.perf_counter()
|
||
seen = []
|
||
for x in items:
|
||
if x not in pool: # O(k)
|
||
seen.append(x)
|
||
return time.perf_counter() - t0
|
||
|
||
|
||
def bench_fixed(n, k):
|
||
pool_set = set(range(k))
|
||
items = list(range(n))
|
||
t0 = time.perf_counter()
|
||
seen = []
|
||
for x in items:
|
||
if x not in pool_set: # O(1)
|
||
seen.append(x)
|
||
return time.perf_counter() - t0
|
||
|
||
|
||
TRIALS = 3
|
||
CASES = [(100, 100), (500, 500), (1000, 1000), (2000, 2000)]
|
||
|
||
|
||
def run():
|
||
lines = []
|
||
header = "=== ruby-0003: RubyGems Gem::Specification#dependent_gems — O(N²×D) nested scan ==="
|
||
print(header); lines.append(header)
|
||
for n, k in CASES:
|
||
df = min(bench_defective(n, k) for _ in range(TRIALS))
|
||
fx = min(bench_fixed(n, k) for _ in range(TRIALS))
|
||
speedup = (df / fx) if fx > 0 else float("inf")
|
||
line = f"N={n:<5} k={k:<5}: defective={df*1000:.3f}ms fixed={fx*1000:.3f}ms speedup={speedup:.1f}x"
|
||
print(line); lines.append(line); sys.stdout.flush()
|
||
return lines
|
||
|
||
|
||
if __name__ == "__main__":
|
||
run()
|