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.
62 lines
2 KiB
Python
62 lines
2 KiB
Python
#!/usr/bin/env python3
|
|
# bench-vitest-0001.py
|
|
# coverage-v8 merged.result.forEach + coverage.result.find per missing entry
|
|
# vs Map<url, result> lookup. Models the V8 coverage merge hot path.
|
|
|
|
import sys
|
|
import time
|
|
|
|
|
|
def bench_defective(n, m):
|
|
"""Array.find per missing-startOffset entry."""
|
|
coverage_result = [{"url": f"file:///src/f{i}.ts", "startOffset": i} for i in range(m)]
|
|
merged = [{"url": f"file:///src/f{i % m}.ts", "startOffset": None} for i in range(n)]
|
|
|
|
t0 = time.perf_counter()
|
|
for r in merged:
|
|
if r["startOffset"] is None:
|
|
original = None
|
|
for orig in coverage_result: # Array.find: O(M)
|
|
if orig["url"] == r["url"]:
|
|
original = orig
|
|
break
|
|
r["startOffset"] = original["startOffset"] if original else 0
|
|
return time.perf_counter() - t0
|
|
|
|
|
|
def bench_fixed(n, m):
|
|
"""Map.get lookup."""
|
|
coverage_result = [{"url": f"file:///src/f{i}.ts", "startOffset": i} for i in range(m)]
|
|
merged = [{"url": f"file:///src/f{i % m}.ts", "startOffset": None} for i in range(n)]
|
|
|
|
t0 = time.perf_counter()
|
|
by_url = {r["url"]: r for r in coverage_result}
|
|
for r in merged:
|
|
if r["startOffset"] is None:
|
|
original = by_url.get(r["url"])
|
|
r["startOffset"] = original["startOffset"] if original else 0
|
|
return time.perf_counter() - t0
|
|
|
|
|
|
TRIALS = 3
|
|
SIZES = [100, 500, 1000, 5000, 10000]
|
|
|
|
|
|
def run():
|
|
lines = []
|
|
header = "=== vitest-0001: coverage-v8 Array.find vs Map<url, result> ==="
|
|
print(header); lines.append(header)
|
|
|
|
for n in SIZES:
|
|
m = n
|
|
d = min(bench_defective(n, m) for _ in range(TRIALS))
|
|
f = min(bench_fixed(n, m) for _ in range(TRIALS))
|
|
speedup = (d / f) if f > 0 else float("inf")
|
|
line = f"N=M={n:<6}: 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()
|