Expand description
Boilerplate-killer for perf examples. Most recipe benches follow one of two shapes:
- Keyed: generate N keys with
SubMsLcg, time eachop(&key). Common for hash maps, bloom filters, caches, dedup gates. - Indexed: call
op(i)fori in 0..N, time each. Common for sequential workloads (arena allocations, ring-buffer enqueues, fixed-size record reads).
Both shapes used to repeat ~6 lines per stage in every
examples/perf_main.rs. These helpers collapse that to one call.
use subms::{SubMsLcg, SubMsPerfHarness, bench_keyed_op, bench_indexed_op};
let mut h = SubMsPerfHarness::new("my-recipe", "rust");
let mut data_structure = std::collections::HashMap::new();
// 50k keyed adds:
bench_keyed_op(&mut h, "add", 50_000, 0, |key| {
data_structure.insert(key.to_string(), 1u32);
});
// 50k indexed ops:
bench_indexed_op(&mut h, "scan", 50_000, |i| {
let _ = data_structure.get(&format!("k{i}"));
});Functions§
- bench_
indexed_ op - Run
counttimed invocations ofop(i)fori in 0..count. Use for indexed sequential workloads (sequential ID generation, fixed record reads, arena allocations). - bench_
keyed_ op - Run
counttimed invocations ofopagainst keys generated by a deterministic LCG seeded withseed. Each key is formatted as"k{u32}". Theopclosure receives the key string by reference. - bench_
templated_ op - Run
counttimed invocations ofopagainst keys formatted from a caller-provided template. Useful when you specifically want negative-lookup keys (“miss-{i}”, “absent-{i}”) that don’t overlap the positive-lookup universe.