Skip to main content

RunInitial

Struct RunInitial 

Source
pub struct RunInitial { /* private fields */ }
Expand description

The first stage of configuring a benchmark run, with all type parameters unknown.

Implementations§

Source§

impl RunInitial

Source

pub fn groups(self, n: NonZero<usize>) -> Self

Divides the threads used for benchmarking into n equal groups. Defaults to 1 group.

The callbacks will be informed of which group they are executing for, and the total number of groups, via a RunMeta parameter.

Attempting to execute a run of a thread pool that is not evenly divisible by n will result in a panic.

Source

pub fn prepare_thread<'a, F, ThreadState>( self, f: F, ) -> RunWithThreadState<'a, ThreadState>
where F: Fn(PrepareThread<'_>) -> ThreadState + Send + Sync + 'a,

Sets the callback used to prepare thread-scoped state for each thread used for benchmarking.

The thread-scoped state is later passed by shared reference to the “prepare iteration” callback when preparing each iteration.

Builder Order: This method can only be called on RunInitial. After calling this, you must use methods from RunWithThreadState for subsequent configuration.

§Examples
use par_bench::Run;

let run = Run::new().prepare_thread(|_| "thread_state").iter(|_| {
    // Thread state is used internally; iter gets unit type by default
    std::hint::black_box(42);
});
Source

pub fn prepare_iter<'a, F, IterState>( self, f: F, ) -> RunWithIterState<'a, (), IterState>
where F: Fn(PrepareIter<'_, ()>) -> IterState + Send + Sync + 'a,

Sets the callback used to prepare iteration-scoped state for each benchmark iteration.

Sets the callback used to prepare iteration-scoped state for each benchmark iteration.

This callback receives a shared reference to the thread-scoped state.

Every iteration is prepared before any iteration is executed.

Builder Order: This method can only be called on a RunInitial (no thread state). After calling this, you must use methods from RunWithIterState for subsequent configuration.

§Examples
use par_bench::Run;

let run = Run::new().prepare_iter(|_| vec![1, 2, 3]).iter(|mut args| {
    // Use the per-iteration vector
    let iter_vec = args.take_iter_state();
    std::hint::black_box(iter_vec.len());
});

If you wish to specify a thread preparation function to provide state for each thread or iteration, do both before calling this method.

Source

pub fn measure_wrapper<'a, FBegin, FEnd, MeasureWrapperState, MeasureOutput>( self, f_begin: FBegin, f_end: FEnd, ) -> RunWithWrapperState<'a, (), (), MeasureWrapperState, MeasureOutput>
where FBegin: Fn(MeasureWrapperBegin<'_, ()>) -> MeasureWrapperState + Send + Sync + 'a, FEnd: Fn(MeasureWrapperState) -> MeasureOutput + Send + Sync + 'a, MeasureOutput: Send + 'static,

Sets the callbacks used to wrap the measured part of a benchmark run, encompassing the execution (but not the preparation) of every iteration.

The f_begin callback is called before the first iteration of each thread, and the f_end callback is called after the last iteration of each thread. Any return value from the former is passed to the latter.

If you wish to specify a thread or iteration preparation function to provide state for each iteration, do it before calling this method.

Source

pub fn iter<'a, F, CleanupState>( self, f: F, ) -> ConfiguredRun<'a, (), (), (), (), CleanupState>
where F: Fn(Iter<'_, (), ()>) -> CleanupState + Send + Sync + 'a,

Sets the callback used to execute the actual benchmark iterations.

This callback may return a value to drop after the measured part of the benchmark run (to exclude any cleanup logic from measurement).

This must be the last step in preparing a benchmark run. After this, the only action permitted is to execute the run.

If you wish to specify a thread or iteration preparation function to provide state for each thread or iteration, or a specify a measurement wrapper function, do all of these before calling this method.

Trait Implementations§

Source§

impl Debug for RunInitial

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> ResourceUsageExt<'a, ()> for RunInitial

Available on crate features all_the_time or alloc_tracker only.
Source§

type Output = RunWithWrapperState<'a, (), (), ResourceUsageState, ResourceUsageOutput>

The type returned when resource usage tracking is configured.
Source§

fn measure_resource_usage<F>( self, operation_name: &'a str, configure: F, ) -> Self::Output

Configures resource usage tracking for the benchmark run. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.