Struct divan::Divan

source ·
pub struct Divan { /* private fields */ }
Expand description

The benchmark runner.

Implementations§

source§

impl Divan

source

pub fn main(&self)

Perform the configured action.

By default, this will be Divan::run_benches.

source

pub fn run_benches(&self)

Benchmark registered functions.

source

pub fn test_benches(&self)

Test registered functions as if the --test flag was used.

Unlike Divan::run_benches, this runs each benchmarked function only once.

source

pub fn list_benches(&self)

Print registered functions as if the --list flag was used.

source§

impl Divan

Configuration options.

source

pub fn from_args() -> Self

Creates an instance with options set by parsing CLI arguments.

source

pub fn config_with_args(self) -> Self

Sets options by parsing CLI arguments.

This may override any previously-set options.

source

pub fn color(self, yes: impl Into<Option<bool>>) -> Self

Sets whether output should be colored.

This option is equivalent to the --color CLI argument, where None here means “auto”.

source

pub fn run_ignored(self) -> Self

Also run benchmarks marked #[ignore].

This option is equivalent to the --include-ignored CLI argument.

source

pub fn run_only_ignored(self) -> Self

Only run benchmarks marked #[ignore].

This option is equivalent to the --ignored CLI argument.

source

pub fn skip_regex(self, filter: impl SkipRegex) -> Self

Skips benchmarks that match filter as a regular expression pattern.

This option is equivalent to the --skip filter CLI argument, without --exact.

§Examples

This method is commonly used with a &str or String:

let filter = "(add|sub)";
let divan = Divan::default().skip_regex(filter);

A pre-built Regex can also be provided:

let filter = regex::Regex::new("(add|sub)").unwrap();
let divan = Divan::default().skip_regex(filter);

Calling this repeatedly will add multiple skip filters:

let divan = Divan::default()
    .skip_regex("(add|sub)")
    .skip_regex("collections.*default");
§Panics

Panics if filter is a string and Regex::new fails.

source

pub fn skip_exact(self, filter: impl Into<String>) -> Self

Skips benchmarks that exactly match filter.

This option is equivalent to the --skip filter --exact CLI arguments.

§Examples

This method is commonly used with a &str or String:

let filter = "arithmetic::add";
let divan = Divan::default().skip_exact(filter);

Calling this repeatedly will add multiple skip filters:

let divan = Divan::default()
    .skip_exact("arithmetic::add")
    .skip_exact("collections::vec::default");
source

pub fn sample_count(self, count: u32) -> Self

Sets the number of sampling iterations.

This option is equivalent to the --sample-count CLI argument.

If a benchmark enables threads, sample count becomes a multiple of the number of threads. This is because each thread operates over the same sample size to ensure there are always N competing threads doing the same amount of work.

source

pub fn sample_size(self, count: u32) -> Self

Sets the number of iterations inside a single sample.

This option is equivalent to the --sample-size CLI argument.

source

pub fn threads<T>(self, threads: T) -> Self
where T: IntoIterator<Item = usize>,

Run across multiple threads.

This enables you to measure contention on atomics and locks. A value of 0 indicates available parallelism.

This option is equivalent to the --threads CLI argument or DIVAN_THREADS environment variable.

source

pub fn min_time(self, time: Duration) -> Self

Sets the time floor for benchmarking a function.

This option is equivalent to the --min-time CLI argument.

source

pub fn max_time(self, time: Duration) -> Self

Sets the time ceiling for benchmarking a function.

This option is equivalent to the --max-time CLI argument.

source

pub fn skip_ext_time(self, skip: bool) -> Self

When accounting for min_time or max_time, skip time external to benchmarked functions.

This option is equivalent to the --skip-ext-time CLI argument.

source§

impl Divan

Use Counters to get throughput across all benchmarks.

source

pub fn counter<C: IntoCounter>(self, counter: C) -> Self

Counts the number of values processed.

source

pub fn items_count<C: Into<ItemsCount>>(self, count: C) -> Self

Sets the number of items processed.

This option is equivalent to the --items-count CLI argument or DIVAN_ITEMS_COUNT environment variable.

source

pub fn bytes_count<C: Into<BytesCount>>(self, count: C) -> Self

Sets the number of bytes processed.

This option is equivalent to the --bytes-count CLI argument or DIVAN_BYTES_COUNT environment variable.

source

pub fn bytes_format(self, format: BytesFormat) -> Self

Determines how BytesCount is scaled in benchmark outputs.

This option is equivalent to the --bytes-format CLI argument or DIVAN_BYTES_FORMAT environment variable.

source

pub fn chars_count<C: Into<CharsCount>>(self, count: C) -> Self

Sets the number of bytes processed.

This option is equivalent to the --chars-count CLI argument or DIVAN_CHARS_COUNT environment variable.

Trait Implementations§

source§

impl Debug for Divan

source§

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

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

impl Default for Divan

source§

fn default() -> Divan

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Divan

§

impl Send for Divan

§

impl Sync for Divan

§

impl Unpin for Divan

§

impl UnwindSafe for Divan

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.