RunSummary

Struct RunSummary 

Source
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>

Source

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);
Source

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);
}
Source

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§

Source§

impl<MeasureOutput: Debug> Debug for RunSummary<MeasureOutput>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V