| 1 | use crate::{PlotConfiguration, SamplingMode}; |
| 2 | use std::time::Duration; |
| 3 | |
| 4 | // TODO: Move the benchmark config stuff to a separate module for easier use. |
| 5 | |
| 6 | /// Struct containing all of the configuration options for a benchmark. |
| 7 | pub struct BenchmarkConfig { |
| 8 | pub confidence_level: f64, |
| 9 | pub measurement_time: Duration, |
| 10 | pub noise_threshold: f64, |
| 11 | pub nresamples: usize, |
| 12 | pub sample_size: usize, |
| 13 | pub significance_level: f64, |
| 14 | pub warm_up_time: Duration, |
| 15 | pub sampling_mode: SamplingMode, |
| 16 | pub quick_mode: bool, |
| 17 | } |
| 18 | |
| 19 | /// Struct representing a partially-complete per-benchmark configuration. |
| 20 | #[derive(Clone, Default)] |
| 21 | pub(crate) struct PartialBenchmarkConfig { |
| 22 | pub(crate) confidence_level: Option<f64>, |
| 23 | pub(crate) measurement_time: Option<Duration>, |
| 24 | pub(crate) noise_threshold: Option<f64>, |
| 25 | pub(crate) nresamples: Option<usize>, |
| 26 | pub(crate) sample_size: Option<usize>, |
| 27 | pub(crate) significance_level: Option<f64>, |
| 28 | pub(crate) warm_up_time: Option<Duration>, |
| 29 | pub(crate) sampling_mode: Option<SamplingMode>, |
| 30 | pub(crate) quick_mode: Option<bool>, |
| 31 | pub(crate) plot_config: PlotConfiguration, |
| 32 | } |
| 33 | |
| 34 | impl PartialBenchmarkConfig { |
| 35 | pub(crate) fn to_complete(&self, defaults: &BenchmarkConfig) -> BenchmarkConfig { |
| 36 | BenchmarkConfig { |
| 37 | confidence_level: self.confidence_level.unwrap_or(defaults.confidence_level), |
| 38 | measurement_time: self.measurement_time.unwrap_or(defaults.measurement_time), |
| 39 | noise_threshold: self.noise_threshold.unwrap_or(defaults.noise_threshold), |
| 40 | nresamples: self.nresamples.unwrap_or(defaults.nresamples), |
| 41 | sample_size: self.sample_size.unwrap_or(defaults.sample_size), |
| 42 | significance_level: self |
| 43 | .significance_level |
| 44 | .unwrap_or(defaults.significance_level), |
| 45 | warm_up_time: self.warm_up_time.unwrap_or(defaults.warm_up_time), |
| 46 | sampling_mode: self.sampling_mode.unwrap_or(defaults.sampling_mode), |
| 47 | quick_mode: self.quick_mode.unwrap_or(defaults.quick_mode), |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |