benches: add SMARM_BENCH_SETS (default 5) for stable medians

Each run_n call now collects ITERS × SETS raw samples across all sets
(one warmup before the first set, discarded), then takes a single global
median. Previously only ITERS=15 samples were taken per bench invocation,
which produced noisy results in sweep.py regress.

SMARM_BENCH_SETS is read from the environment; the default of 5 gives
75 samples per bench row (5×15), matching the stability of the multi-run
bash approach without requiring multiple cargo bench invocations.

Also moves scripts/bench_rq.sh into benches/ alongside sweep.py.
The cd "$(dirname "$0")/.." path logic is unchanged.
This commit is contained in:
Claude
2026-06-11 20:50:29 +00:00
parent 37d931968e
commit f9f60a43d1
4 changed files with 56 additions and 21 deletions
+19 -7
View File
@@ -40,6 +40,13 @@ fn available_threads() -> usize {
std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1)
}
fn env_sets() -> u32 {
std::env::var("SMARM_BENCH_SETS")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(5)
}
fn print_header(title: &str) {
println!("\n{}", "=".repeat(80));
println!(" {title}");
@@ -52,13 +59,17 @@ fn print_header(title: &str) {
}
fn run_n<F: FnMut() -> (u64, u128)>(name: &str, n: u32, mut f: F) {
let mut times = Vec::new();
let sets = env_sets();
let mut times = Vec::with_capacity((n * sets) as usize);
let mut last = 0u64;
let _ = f(); // warmup
for _ in 0..n {
let (v, t) = f();
times.push(t);
last = v;
// One warmup before all sets, discarded.
let _ = f();
for _ in 0..sets {
for _ in 0..n {
let (v, t) = f();
times.push(t);
last = v;
}
}
times.sort_unstable();
let median = times[times.len() / 2];
@@ -385,7 +396,8 @@ fn main() {
let n = available_threads();
println!("smarm smarm-favored benchmarks");
println!("available parallelism: {n} threads");
println!("ITERS={ITERS} (+1 warmup, discarded)");
let sets = env_sets();
println!("ITERS={ITERS}×{sets} sets = {} samples (+1 warmup, discarded)", ITERS * sets);
println!(
"RECURSE_DEPTH={RECURSE_DEPTH}, HOT_YIELDS={HOT_YIELDS}×2, \
UNCONT_MSGS={UNCONT_MSGS}, PANIC_TASKS={PANIC_TASKS}"