Skip to main content

Bencher

Struct Bencher 

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

The Bencher provides iteration control for benchmarks.

The benchmark body calls exactly one iter* method once. That method runs warmup and measurement in full before it returns. Each sample holds per-iteration means over one batch of calls.

Implementations§

Source§

impl Bencher

Source

pub fn attach_runtime(&mut self, rt: Arc<Runtime>)

Attach the runtime that iter_async runs on.

The #[flux::bench] wrapper attaches the runtime it builds.

Source

pub fn attach_runtime_error(&mut self, message: impl Into<String>)

Record a runtime build error. finish returns it as MeasureError::AsyncRuntime.

Source

pub fn iter_async<T, F, Fut>(&mut self, f: F)
where F: FnMut() -> Fut, Fut: Future<Output = T>,

Measure an async closure. Each batch awaits n calls inside one block_on.

The timer covers creating and awaiting each future. It runs on the attached runtime. Without one, it builds a current-thread runtime once and keeps it. Call it from sync code or from a body that drive_async_body runs. A call inside a runtime context records MeasureError::AsyncRuntime and runs nothing.

Source

pub fn iter_async_standalone<T, F, Fut>(&mut self, f: F)
where F: FnMut() -> Fut, Fut: Future<Output = T>,

👎Deprecated:

use iter_async

Measure an async closure. Same as iter_async.

Source§

impl Bencher

Source

pub fn iter_with_setup<T, S, F, R>(&mut self, setup: S, routine: F)
where S: FnMut() -> T, F: FnMut(T) -> R,

Measure routine on fresh inputs from setup. Setup time is excluded.

Same as iter_batched(setup, routine, BatchSize::SmallInput).

Source

pub fn iter_batched<T, S, F, R>( &mut self, setup: S, routine: F, size: BatchSize, )
where S: FnMut() -> T, F: FnMut(T) -> R,

Measure routine on inputs it takes by value. Setup time is excluded.

setup runs once per call. It builds each batch of inputs untimed. size sets the inputs per batch. One timer covers the routine over a batch. Outputs drop after the timer stops.

Source

pub fn iter_batched_ref<T, S, F, R>( &mut self, setup: S, routine: F, size: BatchSize, )
where S: FnMut() -> T, F: FnMut(&mut T) -> R,

Measure routine on inputs it borrows mutably. Setup time is excluded.

Same batching as iter_batched. Inputs and outputs drop after the timer stops.

Source

pub fn iter_batched_shared<T, S, F, R>( &mut self, batch_size: u64, setup: S, routine: F, )
where S: FnMut() -> T, F: FnMut(&T) -> R,

Measure routine on a shared input that setup rebuilds every batch_size calls.

batch_size sets only the setup cadence. A value of 0 rises to 1. Each sample calls setup ceil(iters_per_sample / batch_size) times, untimed.

Source§

impl Bencher

Source

pub fn iter_custom<F>(&mut self, routine: F)
where F: FnMut(u64) -> Duration,

Measure a routine that times itself.

routine(iters) runs iters calls and returns the time they took. The engine runs warmup, sizes the samples, and calls it once per batch. The returned time is the sample total. No engine timer overhead is removed from it. Allocation counters cover the whole routine call. Cycle counts are 0.

Source§

impl Bencher

Source

pub fn iter<T, F>(&mut self, f: F)
where F: FnMut() -> T,

Measure f. This call runs warmup and every sample.

One timer pair covers a whole batch of calls. Each sample holds the per-iteration mean of that batch.

Source§

impl Bencher

Source

pub fn new(track_allocations: bool) -> Self

Create a Bencher with the default config and the given allocation tracking.

Source

pub fn with_config(config: MeasureConfig) -> Self

Create a Bencher from a measurement config.

The config is normalized first: see MeasureConfig::normalized.

Source

pub fn throughput(&mut self, throughput: Throughput)

Set the work one routine call processes. Reports turn it into a rate per second.

Call it anywhere in the body. The last call wins. It overrides throughput_bytes or throughput_elements on #[flux::bench] and #[flux::group].

Source

pub fn with_sample_sink(self, sink: impl SampleSink + 'static) -> Self

Send each recorded sample to sink during measurement.

The sink runs between samples, outside every timed region. Samples still land in the result as before.

Source

pub fn with_sample_count(track_allocations: bool, sample_count: usize) -> Self

Create a Bencher that targets sample_count samples. Other values are defaults.

The count has no upper cap. Values below MIN_SAMPLE_COUNT rise to it.

Source

pub fn for_config( track_allocations: bool, sample_count: usize, iters_per_sample: Option<u64>, ) -> Self

Create a Bencher from sample values. Times and iteration limits are defaults.

Some(n) iterations per sample selects fixed mode. None selects time-based mode.

Source

pub fn with_fixed_iters_per_sample(self, iters: u64) -> Self

Fix the iterations per sample. This selects fixed mode: no warmup, no estimation.

A value of 0 rises to 1.

Source

pub fn config(&self) -> &MeasureConfig

The normalized measurement config

Source

pub fn fixed_iters_per_sample(&self) -> Option<u64>

Fixed iterations per sample, if fixed mode is on

Source

pub fn target_samples(&self) -> usize

Target sample count

Source

pub fn samples(&self) -> &[Sample]

Collected samples

Source

pub fn iteration_count(&self) -> u64

Routine calls in the measurement phase so far. Warmup calls are excluded.

Source

pub fn record_error(&mut self, error: MeasureError)

Record an error for finish to return. The first error wins.

Source

pub fn finish(self) -> Result<BenchmarkResult, MeasureError>

Assemble the result, or return the first error the body caused.

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.