java-topology/defects/vagrant/bench/bench-vagrant-0001.py
russell@unturf.com 33cc466b3a
wave5: vagrant-0001 flagship + 32-target CI/CD/IaC scan survey
vagrant-0001: bundler.rb plugin loader runs Array#include? against
plugins.keys / system_plugins inside per-spec loops. O(S*P) per
vagrant command. Fix: hoist Set.new outside the loop, O(1) per
spec lookup. Bench: 127x at S=2000 P=1000.

wave5-cicd-iac-survey.md: documents 32 projects scanned across
deployment (Spinnaker, fluxcd, Argo Rollouts/Events), modern CI/CD
(Earthly, Dagger, Buck2), container runtime (containerd, crun,
skopeo, ko, kaniko, buildah), local k8s (kind, minikube, k3s),
IaC + testing (Packer, Vagrant, ansible-lint, Molecule, InSpec,
Terratest), contract/mutation testing (Pact, Stryker, mutmut,
PIT), security (Semgrep, Bandit, gosec), Java quality (Spotbugs,
Checkstyle, chart-testing).

Clean-scan honor roll +4: chart-testing, kind, ko, pact-ruby.
2026-04-25 10:01:56 -04:00

55 lines
1.7 KiB
Python

#!/usr/bin/env python3
# bench-vagrant-0001.py
# Bundler plugin loader: plugins.keys.include?(spec.name) inside a per-spec
# loop. O(S*P) for S resolved specs and P plugins. Fix: hoist Set, O(1)
# per spec.
import sys
import time
def bench_defective(s_specs, p_plugins):
plugin_keys = [f"plugin_{i:03d}" for i in range(p_plugins)]
specs = [f"plugin_{(i * 7) % p_plugins:03d}" for i in range(s_specs)]
t0 = time.perf_counter()
matched = []
for spec in specs:
# Ruby Array#include? = Python list __contains__ = O(P)
if spec in plugin_keys:
matched.append(spec)
return time.perf_counter() - t0
def bench_fixed(s_specs, p_plugins):
plugin_keys = [f"plugin_{i:03d}" for i in range(p_plugins)]
specs = [f"plugin_{(i * 7) % p_plugins:03d}" for i in range(s_specs)]
t0 = time.perf_counter()
plugin_set = set(plugin_keys)
matched = []
for spec in specs:
if spec in plugin_set: # Set#include? = O(1)
matched.append(spec)
return time.perf_counter() - t0
TRIALS = 3
CASES = [(50, 50), (200, 100), (500, 200), (1000, 500), (2000, 1000)]
def run():
lines = []
header = "=== vagrant-0001: Bundler plugin Array#include? vs Set#include? ==="
print(header); lines.append(header)
for s, p in CASES:
df = min(bench_defective(s, p) for _ in range(TRIALS))
fx = min(bench_fixed(s, p) for _ in range(TRIALS))
speedup = (df / fx) if fx > 0 else float("inf")
line = f"S={s:<5} P={p:<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()