macro_rules! queuecheck_bench_latency {
($pairs:expr, $producers:expr, $consumers:expr, $produce:expr, $consume:expr) => { ... };
}
Expand description
Benchmarks the latency of the supplied queue.
§Example
The below benchmarks the latency of the unbounded MPMC queue from the standard library by producing 100,000 items using two producer threads which are then consumed by one consumer thread.
use std::sync::mpsc::{self, Receiver, Sender};
let (producer, consumer) = mpsc::channel();
let latency = queuecheck_bench_latency!(
// warmup and measurement enqueue/dequeue operation pairs
(1_000, 100_000),
// producer threads
vec![producer.clone(), producer],
// consumer threads
vec![consumer],
// produce operation
|p: &Sender<i32>, i: i32| p.send(i).unwrap(),
// consume operation
|c: &Receiver<i32>| c.try_recv().ok()
);
latency.report("mpmc", &[50.0, 70.0, 90.0, 95.0, 99.09]);
§Sample Output
mpmc
produce
50%: 239.00ns
70%: 253.00ns
90%: 278.00ns
95%: 294.00ns
99%: 970.00ns
consume
50%: 178.00ns
70%: 249.00ns
90%: 279.00ns
95%: 295.00ns
99%: 1_578.00ns