pub fn run<A>(workload: Workload, config: &Config, make_alloc: fn() -> A) -> f64where
A: GlobalAlloc + Send + 'static,Expand description
Run one workload × allocator × thread-count and return aggregate ops/sec.
A is your allocator — typically a ZST (System, mimalloc::MiMalloc,
etc.). A fresh instance is constructed per thread via make_alloc.
The harness:
- Spawns
config.threadsworkers, each with its own mailbox channel for cross-thread block handoff. - Uses a
Barrierso all workers start the timed region together (eliminates thread-spawn skew from the measurement). - Sums total ops across all workers and divides by wall-clock elapsed.
§Safety contract upheld by the harness
Every block allocated by A::alloc is freed exactly once by exactly one
thread via A::dealloc. The harness manages ownership bookkeeping (slot
Option discipline + mpsc transfer) so callers do not need to.
The harness itself calls A::alloc / A::dealloc (the GlobalAlloc
trait is unsafe); those calls follow the safety contracts of
GlobalAlloc.
§Example
use malloc_bench_rs::{run, Config, Workload};
use std::alloc::System;
let cfg = Config { threads: 1, steps_per_thread: 1_000, working_set: 64, mstress_blocks: 32 };
let ops = run(Workload::Larson, &cfg, || System);
assert!(ops > 0.0);