use std::{borrow::Cow, time::Duration};
use crate::{counter::CounterSet, time::FineDuration};
#[derive(Clone, Default)]
pub struct BenchOptions<'a> {
pub sample_count: Option<u32>,
pub sample_size: Option<u32>,
pub threads: Option<Cow<'a, [usize]>>,
pub counters: CounterSet,
pub min_time: Option<Duration>,
pub max_time: Option<Duration>,
pub skip_ext_time: Option<bool>,
pub ignore: Option<bool>,
}
impl<'a> BenchOptions<'a> {
#[must_use]
pub(crate) fn overwrite<'b>(&'b self, other: &'b Self) -> Self
where
'b: 'a,
{
Self {
sample_count: self.sample_count.or(other.sample_count),
sample_size: self.sample_size.or(other.sample_size),
threads: self.threads.as_deref().or(other.threads.as_deref()).map(Cow::Borrowed),
min_time: self.min_time.or(other.min_time),
max_time: self.max_time.or(other.max_time),
skip_ext_time: self.skip_ext_time.or(other.skip_ext_time),
ignore: self.ignore.or(other.ignore),
counters: self.counters.overwrite(&other.counters),
}
}
#[inline]
pub(crate) fn has_samples(&self) -> bool {
self.sample_count != Some(0) && self.sample_size != Some(0)
}
#[inline]
pub(crate) fn min_time(&self) -> FineDuration {
self.min_time.map(FineDuration::from).unwrap_or_default()
}
#[inline]
pub(crate) fn max_time(&self) -> FineDuration {
self.max_time.map(FineDuration::from).unwrap_or(FineDuration::MAX)
}
}