Closes the three tractable pending buckets (all non-no_dir work):
+ lean4-0004..0007: 4 correctness/race benches (ir_interp DCL, jobreg
IO.Ref race, g_opts thread-local leakage, process envvar hash).
lean4-0007 shows 138x O(N^2)->O(N); 0004-0006 demonstrate lost
updates/leaks of several hundred in defective, 0 in fixed.
+ 0ad-0001..0004: 3 CWE-407 list.find->unordered_set speedup benches
(obstruction dirty shapes, modified entities, template cache) at
70-341x, plus 0ad-0004 log-redaction correctness at 100% redaction.
+ activemq-0001..0003: 3 CWE-407 benches (queue/topic consumer rotation,
demand-bridge candidate dedup, transaction-context endedXA set) at
95-178x.
+ linux-0001..0008: 8 Python complexity-class models for the kernel
patches. Coexist with the existing build-and-bench.sh kernel-level
bench; the Python models give 10-389x and the generator embeds them.
+ mercurial-0001-0001: standalone graphmod O(k^2)->O(k) model at
3-20x, alongside the existing bench_google_scale.py (which imports
the real mercurial graphmod).
Progress: 13 -> 33 full coverage. Remaining pending: 1262 no_dir +
12 non-CWE-407 race/leaked-context defects (future work on per-MOAD
bench templates).
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
# bench-activemq-0003.py
|
|
# TransactionContext endedXATransactions List: .contains check before add on
|
|
# a growing ended-XA-txn list. Per-transaction O(N) check over all prior
|
|
# endings; fix is a parallel HashSet for O(1) membership.
|
|
|
|
import sys
|
|
import time
|
|
|
|
|
|
def bench_defective(n):
|
|
ended = []
|
|
incoming = [f"xid_{i:06d}" for i in range(n)]
|
|
t0 = time.perf_counter()
|
|
for xid in incoming:
|
|
if xid not in ended: # O(|ended|)
|
|
ended.append(xid)
|
|
return time.perf_counter() - t0
|
|
|
|
|
|
def bench_fixed(n):
|
|
ended_set = set()
|
|
ended = []
|
|
incoming = [f"xid_{i:06d}" for i in range(n)]
|
|
t0 = time.perf_counter()
|
|
for xid in incoming:
|
|
if xid not in ended_set:
|
|
ended_set.add(xid)
|
|
ended.append(xid)
|
|
return time.perf_counter() - t0
|
|
|
|
|
|
TRIALS = 3
|
|
SIZES = [100, 500, 1000, 2000]
|
|
|
|
|
|
def run():
|
|
lines = []
|
|
header = "=== activemq-0003: TransactionContext endedXATransactions List.contains vs HashSet ==="
|
|
print(header); lines.append(header)
|
|
for n in SIZES:
|
|
df = min(bench_defective(n) for _ in range(TRIALS))
|
|
fx = min(bench_fixed(n) for _ in range(TRIALS))
|
|
speedup = (df / fx) if fx > 0 else float("inf")
|
|
line = f"N={n:<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()
|