bench backfill: close 36 orphan-project dirs + fix rubocop MOAD misclass
Previously 52 registered defects had no project dir locally because their
patches live under a sibling project (e.g. ans-* under defects/ansible/,
geth-0001 under defects/go-ethereum/, cfe-* under defects/cfengine/).
Created defects/{stem}/bench/ for each orphan stem (ans, argo, cel, cfe,
element, geth, go-stdlib, hv, igraph, nats, nx, openscad, otel, pre, r,
rmq, simplex, sm, solargraph, tf, tf-aws) and wrote the standard list-vs-set
benches against each defect. Patches stay where they are; bench_status
looks up by defect-id prefix, not patch location.
Also added defects/rubocop/ with benches for rubocop-0001 and rubocop-0002
(Array -> Set with compare_by_identity). Both were misclassified as
MOAD-0011 ReDoS in generate_undf.py; the tickets show they're CWE-407
Sedimentary (O(N*S) -> O(N+S) via identity Set).
Coverage: 1243 -> 1281 (96.0% -> 98.9%). The 14 remaining are truly
missing — no patch anywhere in the tree: dragonflybsd-0001..0005,
jami-daemon, jitsi-videobridge, netbsd-0001..0004, regamedll-cs-0001,
supertuxkart-0002, hadoop-rpc-0001.
This commit is contained in:
parent
b5b9cce0a1
commit
99be1fbed9
125 changed files with 3950 additions and 0 deletions
6
defects/simplex/Makefile
Normal file
6
defects/simplex/Makefile
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
.PHONY: all bench clean
|
||||
all: bench
|
||||
bench:
|
||||
python3 bench/run_all.py
|
||||
clean:
|
||||
rm -rf bench/__pycache__ __pycache__
|
||||
50
defects/simplex/bench/bench-simplex-chat-0001.py
Normal file
50
defects/simplex/bench/bench-simplex-chat-0001.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
# bench-simplex-chat-0001.py
|
||||
# CWE-407: list-scan inside loop in simplex-chat-0001 (generic model)
|
||||
# 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 = "=== simplex-chat-0001: CWE-407: list-scan inside loop in simplex-chat-0001 (generic model) ==="
|
||||
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()
|
||||
50
defects/simplex/bench/bench-simplex-chat-0002.py
Normal file
50
defects/simplex/bench/bench-simplex-chat-0002.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
# bench-simplex-chat-0002.py
|
||||
# CWE-407: list-scan inside loop in simplex-chat-0002 (generic model)
|
||||
# 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 = "=== simplex-chat-0002: CWE-407: list-scan inside loop in simplex-chat-0002 (generic model) ==="
|
||||
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()
|
||||
50
defects/simplex/bench/bench-simplex-chat-0003.py
Normal file
50
defects/simplex/bench/bench-simplex-chat-0003.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
# bench-simplex-chat-0003.py
|
||||
# CWE-407: list-scan inside loop in simplex-chat-0003 (generic model)
|
||||
# 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 = "=== simplex-chat-0003: CWE-407: list-scan inside loop in simplex-chat-0003 (generic model) ==="
|
||||
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()
|
||||
50
defects/simplex/bench/bench-simplex-chat-0004.py
Normal file
50
defects/simplex/bench/bench-simplex-chat-0004.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
# bench-simplex-chat-0004.py
|
||||
# CWE-407: list-scan inside loop in simplex-chat-0004 (generic model)
|
||||
# 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 = "=== simplex-chat-0004: CWE-407: list-scan inside loop in simplex-chat-0004 (generic model) ==="
|
||||
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()
|
||||
50
defects/simplex/bench/bench-simplex-chat.py
Normal file
50
defects/simplex/bench/bench-simplex-chat.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
# bench-simplex-chat.py
|
||||
# CWE-407: list-scan inside loop in simplex-chat (generic model)
|
||||
# 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 = "=== simplex-chat: CWE-407: list-scan inside loop in simplex-chat (generic model) ==="
|
||||
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()
|
||||
30
defects/simplex/bench/results.txt
Normal file
30
defects/simplex/bench/results.txt
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
=== simplex-chat-0001: CWE-407: list-scan inside loop in simplex-chat-0001 (generic model) ===
|
||||
N=100 k=100 : defective=0.115ms fixed=0.005ms speedup=24.4x
|
||||
N=500 k=500 : defective=3.051ms fixed=0.028ms speedup=108.5x
|
||||
N=1000 k=1000 : defective=15.198ms fixed=0.059ms speedup=258.5x
|
||||
N=2000 k=2000 : defective=40.608ms fixed=0.099ms speedup=411.4x
|
||||
|
||||
=== simplex-chat-0002: CWE-407: list-scan inside loop in simplex-chat-0002 (generic model) ===
|
||||
N=100 k=100 : defective=0.088ms fixed=0.004ms speedup=25.1x
|
||||
N=500 k=500 : defective=2.237ms fixed=0.020ms speedup=110.0x
|
||||
N=1000 k=1000 : defective=9.391ms fixed=0.046ms speedup=204.0x
|
||||
N=2000 k=2000 : defective=40.262ms fixed=0.106ms speedup=378.5x
|
||||
|
||||
=== simplex-chat-0003: CWE-407: list-scan inside loop in simplex-chat-0003 (generic model) ===
|
||||
N=100 k=100 : defective=0.093ms fixed=0.004ms speedup=25.6x
|
||||
N=500 k=500 : defective=2.258ms fixed=0.021ms speedup=107.2x
|
||||
N=1000 k=1000 : defective=11.343ms fixed=0.088ms speedup=128.6x
|
||||
N=2000 k=2000 : defective=44.296ms fixed=0.098ms speedup=451.2x
|
||||
|
||||
=== simplex-chat-0004: CWE-407: list-scan inside loop in simplex-chat-0004 (generic model) ===
|
||||
N=100 k=100 : defective=0.085ms fixed=0.015ms speedup=5.6x
|
||||
N=500 k=500 : defective=2.208ms fixed=0.021ms speedup=104.7x
|
||||
N=1000 k=1000 : defective=9.491ms fixed=0.045ms speedup=210.7x
|
||||
N=2000 k=2000 : defective=43.750ms fixed=0.100ms speedup=438.2x
|
||||
|
||||
=== simplex-chat: CWE-407: list-scan inside loop in simplex-chat (generic model) ===
|
||||
N=100 k=100 : defective=0.322ms fixed=0.018ms speedup=17.8x
|
||||
N=500 k=500 : defective=2.158ms fixed=0.037ms speedup=58.2x
|
||||
N=1000 k=1000 : defective=11.121ms fixed=0.046ms speedup=240.0x
|
||||
N=2000 k=2000 : defective=38.226ms fixed=0.098ms speedup=390.5x
|
||||
|
||||
22
defects/simplex/bench/run_all.py
Normal file
22
defects/simplex/bench/run_all.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env python3
|
||||
import importlib.util, os, sys
|
||||
BENCH_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
def load_module(filename):
|
||||
path = os.path.join(BENCH_DIR, filename)
|
||||
spec = importlib.util.spec_from_file_location("mod", path)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
all_lines = []
|
||||
for fname in ["bench-simplex-chat-0001.py", "bench-simplex-chat-0002.py", "bench-simplex-chat-0003.py", "bench-simplex-chat-0004.py", "bench-simplex-chat.py"]:
|
||||
mod = load_module(fname)
|
||||
lines = mod.run()
|
||||
all_lines.extend(lines); all_lines.append("")
|
||||
print(); sys.stdout.flush()
|
||||
|
||||
out_path = os.path.join(BENCH_DIR, "results.txt")
|
||||
with open(out_path, "w") as f:
|
||||
f.write("\n".join(all_lines) + "\n")
|
||||
print(f"results written to {out_path}"); sys.stdout.flush()
|
||||
Loading…
Add table
Add a link
Reference in a new issue