pub struct Divan { /* private fields */ }Expand description
The benchmark runner.
Implementations§
Source§impl Divan
impl Divan
Sourcepub fn main(&self)
pub fn main(&self)
Perform the configured action.
By default, this will be Divan::run_benches.
Sourcepub fn run_benches(&self)
pub fn run_benches(&self)
Benchmark registered functions.
Sourcepub fn test_benches(&self)
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.
Sourcepub fn list_benches(&self)
pub fn list_benches(&self)
Print registered functions as if the --list flag was used.
Source§impl Divan
Configuration options.
impl Divan
Configuration options.
Sourcepub fn config_with_args(self) -> Divan
pub fn config_with_args(self) -> Divan
Sets options by parsing CLI arguments.
This may override any previously-set options.
Sourcepub fn color(self, yes: impl Into<Option<bool>>) -> Divan
pub fn color(self, yes: impl Into<Option<bool>>) -> Divan
Sets whether output should be colored.
This option is equivalent to the --color CLI argument, where None
here means “auto”.
Sourcepub fn run_ignored(self) -> Divan
pub fn run_ignored(self) -> Divan
Also run benchmarks marked #[ignore].
This option is equivalent to the --include-ignored CLI argument.
Sourcepub fn run_only_ignored(self) -> Divan
pub fn run_only_ignored(self) -> Divan
Only run benchmarks marked #[ignore].
This option is equivalent to the --ignored CLI argument.
Sourcepub fn skip_regex(self, filter: impl SkipRegex) -> Divan
pub fn skip_regex(self, filter: impl SkipRegex) -> Divan
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.
Sourcepub fn skip_exact(self, filter: impl Into<String>) -> Divan
pub fn skip_exact(self, filter: impl Into<String>) -> Divan
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");Sourcepub fn sample_count(self, count: u32) -> Divan
pub fn sample_count(self, count: u32) -> Divan
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.
Sourcepub fn sample_size(self, count: u32) -> Divan
pub fn sample_size(self, count: u32) -> Divan
Sets the number of iterations inside a single sample.
This option is equivalent to the --sample-size CLI argument.
Sourcepub fn threads<T>(self, threads: T) -> Divanwhere
T: IntoIterator<Item = usize>,
pub fn threads<T>(self, threads: T) -> Divanwhere
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.
Sourcepub fn min_time(self, time: Duration) -> Divan
pub fn min_time(self, time: Duration) -> Divan
Sets the time floor for benchmarking a function.
This option is equivalent to the --min-time CLI argument.
Sourcepub fn max_time(self, time: Duration) -> Divan
pub fn max_time(self, time: Duration) -> Divan
Sets the time ceiling for benchmarking a function.
This option is equivalent to the --max-time CLI argument.
Sourcepub fn skip_ext_time(self, skip: bool) -> Divan
pub fn skip_ext_time(self, skip: bool) -> Divan
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.
impl Divan
Use Counters to get throughput across all
benchmarks.
Sourcepub fn counter<C>(self, counter: C) -> Divanwhere
C: IntoCounter,
pub fn counter<C>(self, counter: C) -> Divanwhere
C: IntoCounter,
Counts the number of values processed.
Sourcepub fn items_count<C>(self, count: C) -> Divanwhere
C: Into<ItemsCount>,
pub fn items_count<C>(self, count: C) -> Divanwhere
C: Into<ItemsCount>,
Sets the number of items processed.
This option is equivalent to the --items-count CLI argument or
DIVAN_ITEMS_COUNT environment variable.
Sourcepub fn bytes_count<C>(self, count: C) -> Divanwhere
C: Into<BytesCount>,
pub fn bytes_count<C>(self, count: C) -> Divanwhere
C: Into<BytesCount>,
Sets the number of bytes processed.
This option is equivalent to the --bytes-count CLI argument or
DIVAN_BYTES_COUNT environment variable.
Sourcepub fn bytes_format(self, format: BytesFormat) -> Divan
pub fn bytes_format(self, format: BytesFormat) -> Divan
Determines how BytesCount is scaled in benchmark outputs.
This option is equivalent to the --bytes-format CLI argument or
DIVAN_BYTES_FORMAT environment variable.
Sourcepub fn chars_count<C>(self, count: C) -> Divanwhere
C: Into<CharsCount>,
pub fn chars_count<C>(self, count: C) -> Divanwhere
C: Into<CharsCount>,
Sets the number of bytes processed.
This option is equivalent to the --chars-count CLI argument or
DIVAN_CHARS_COUNT environment variable.
Sourcepub fn cycles_count<C>(self, count: C) -> Divanwhere
C: Into<CyclesCount>,
pub fn cycles_count<C>(self, count: C) -> Divanwhere
C: Into<CyclesCount>,
Sets the number of cycles processed, displayed as Hertz.
This option is equivalent to the --cycles-count CLI argument or
DIVAN_CYCLES_COUNT environment variable.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Divan
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> 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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.