vitest-0001: coverage-v8 coverage.result.find inside merged.result.forEach -> Map<url, result> lookup. Bench: 824x at N=M=10000 coverage entries. testng-0001: DynamicGraph.toDot freeNodes.contains inside two for-each loops -> Map<T, String> color lookup via getOrDefault. Bench: 64x at N=2000. jasmine-0001: SpyRegistry.spyOnAllFunctions propertiesToSkip.indexOf inside Array.filter + .concat growth across D prototype levels -> Set.has + O(1) growth. Bench: 61x at D=10, P=300. check-0001: libcheck suite_tcase linear strcmp scan over tclst List -> parallel hashtable for O(1) lookup amortized. Bench: 117x at N=1000. Shipped as design sketch; full integration requires companion hashtable. Also ships whitepaper/outreach/test-harness-survey.md documenting 14 clean-scan frameworks across Clojure, OCaml, Haskell, Erlang, Go, F#, Julia, Shell, Lua, JS. Scope covered 61 targets across 30+ languages. UNDF IDs: 1292 (check), 1293 (jasmine), 1294 (testng), 1295 (vitest). All 12 tests pass.
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# bench-check-0001.py
|
|
# libcheck Suite tcase-by-name lookup: linear strcmp scan over List<TCase>
|
|
# vs hashtable lookup. Models the runner filter path.
|
|
|
|
import sys
|
|
import time
|
|
|
|
|
|
def bench_defective(n, lookups):
|
|
"""Linear scan with strcmp per lookup."""
|
|
tcases = [{"name": f"tc_{i:04d}"} for i in range(n)]
|
|
lookup_names = [f"tc_{i:04d}" for i in range(lookups)]
|
|
|
|
t0 = time.perf_counter()
|
|
for tcname in lookup_names:
|
|
found = False
|
|
for tc in tcases: # O(N) scan, strcmp per entry
|
|
if tc["name"] == tcname:
|
|
found = True
|
|
break
|
|
return time.perf_counter() - t0
|
|
|
|
|
|
def bench_fixed(n, lookups):
|
|
"""Hashtable lookup, O(1) amortized."""
|
|
tcases = [{"name": f"tc_{i:04d}"} for i in range(n)]
|
|
lookup_names = [f"tc_{i:04d}" for i in range(lookups)]
|
|
|
|
t0 = time.perf_counter()
|
|
index = {tc["name"]: tc for tc in tcases}
|
|
for tcname in lookup_names:
|
|
found = tcname in index
|
|
return time.perf_counter() - t0
|
|
|
|
|
|
TRIALS = 3
|
|
CASES = [(50, 50), (100, 100), (200, 200), (500, 500), (1000, 1000)]
|
|
|
|
|
|
def run():
|
|
lines = []
|
|
header = "=== check-0001: Suite tcase linear strcmp vs hashtable ==="
|
|
print(header); lines.append(header)
|
|
|
|
for n, l in CASES:
|
|
d = min(bench_defective(n, l) for _ in range(TRIALS))
|
|
f = min(bench_fixed(n, l) for _ in range(TRIALS))
|
|
speedup = (d / f) if f > 0 else float("inf")
|
|
line = f"N={n:<5} lookups={l:<5}: defective={d*1000:.3f}ms fixed={f*1000:.3f}ms speedup={speedup:.1f}x"
|
|
print(line); lines.append(line); sys.stdout.flush()
|
|
|
|
return lines
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run()
|