pub struct RunSummary<MeasureOutput> { /* private fields */ }Expand description
The result of executing a benchmark run, carrying data suitable for ingestion into a benchmark framework.
Contains timing information and any measurement data collected during the run. The timing represents the mean duration across all threads, while measurement outputs contain one entry per thread that participated in the run.
§Examples
use std::time::Duration;
use many_cpus::ProcessorSet;
use par_bench::{Run, ThreadPool};
let mut pool = ThreadPool::new(&ProcessorSet::default());
let results = Run::new()
.measure_wrapper(
|_| std::time::Instant::now(),
|start_time| start_time.elapsed(),
)
.iter(|_| {
// Some work to measure
std::hint::black_box(42 * 42);
})
.execute_on(&mut pool, 1000);
// Get timing information
println!("Mean duration: {:?}", results.mean_duration());
// Process measurement outputs (one per thread)
for (i, elapsed) in results.measure_outputs().enumerate() {
println!("Thread {}: {:?}", i, elapsed);
}Implementations§
Source§impl<MeasureOutput> RunSummary<MeasureOutput>
impl<MeasureOutput> RunSummary<MeasureOutput>
Sourcepub fn mean_duration(&self) -> Duration
pub fn mean_duration(&self) -> Duration
Returns the mean duration of the run.
This represents the average execution time across all threads that participated in the benchmark run. The duration covers only the measured portion of the run (between measurement wrapper begin/end calls).
§Examples
use many_cpus::ProcessorSet;
use par_bench::{Run, ThreadPool};
let mut pool = ThreadPool::new(&ProcessorSet::default());
let results = Run::new()
.iter(|_| std::hint::black_box(42 + 42))
.execute_on(&mut pool, 1000);
let duration = results.mean_duration();
println!("Average time per iteration: {:?}", duration);Sourcepub fn measure_outputs(&self) -> impl Iterator<Item = &MeasureOutput>
pub fn measure_outputs(&self) -> impl Iterator<Item = &MeasureOutput>
Returns the output of the measurement wrapper used for the run.
This will iterate over one measurement output per thread that was involved in the run. The outputs are produced by the measurement wrapper end callback and can contain any thread-specific measurement data.
§Panics
Panics if the measure outputs have already been consumed via take_measure_outputs().
§Examples
use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering};
use many_cpus::ProcessorSet;
use par_bench::{Run, ThreadPool};
let mut pool = ThreadPool::new(&ProcessorSet::default());
let run = Run::new()
.prepare_iter(|_| Arc::new(AtomicU64::new(0)))
.measure_wrapper(
|_| (), // Start measurement
|_state| 42u64, // Return some measurement
)
.iter(|mut args| {
let counter = args.take_iter_state();
counter.fetch_add(1, Ordering::Relaxed);
});
let results = run.execute_on(&mut pool, 1000);
// Each thread's measurement output
for (thread_id, count) in results.measure_outputs().enumerate() {
println!("Thread {} measurement: {}", thread_id, count);
}Sourcepub fn take_measure_outputs(&mut self) -> Box<[MeasureOutput]>
pub fn take_measure_outputs(&mut self) -> Box<[MeasureOutput]>
Takes ownership of the measurement outputs, consuming them from the summary.
Returns a boxed slice containing one measurement output per thread that
participated in the benchmark run. After calling this method, subsequent
calls to measure_outputs() or take_measure_outputs() will panic.
This method is useful when you need to own the measurement data rather than just iterate over references to it.
§Panics
Panics if the measure outputs have already been consumed via a previous
call to take_measure_outputs().
§Examples
use many_cpus::ProcessorSet;
use par_bench::{Run, ThreadPool};
let mut pool = ThreadPool::new(&ProcessorSet::default());
let mut results = Run::new()
.measure_wrapper(
|_| (), // Start measurement
|_state| 42u64, // Return some measurement
)
.iter(|_| std::hint::black_box(42 * 42))
.execute_on(&mut pool, 1000);
// Take ownership of all measurement outputs
let owned_outputs = results.take_measure_outputs();
println!("Collected {} measurements", owned_outputs.len());
// Process the owned data
for (i, measurement) in owned_outputs.iter().enumerate() {
println!("Thread {}: {}", i, measurement);
}Trait Implementations§
Auto Trait Implementations§
impl<MeasureOutput> Freeze for RunSummary<MeasureOutput>
impl<MeasureOutput> RefUnwindSafe for RunSummary<MeasureOutput>where
MeasureOutput: RefUnwindSafe,
impl<MeasureOutput> Send for RunSummary<MeasureOutput>where
MeasureOutput: Send,
impl<MeasureOutput> Sync for RunSummary<MeasureOutput>where
MeasureOutput: Sync,
impl<MeasureOutput> Unpin for RunSummary<MeasureOutput>
impl<MeasureOutput> UnwindSafe for RunSummary<MeasureOutput>where
MeasureOutput: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more