Skip to content
Myr

More simplifications

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent f7e6d72 · Browse files · 5 files+39 added−51 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+39 added−51 removed

  • other:+39 added−51 removed

5 files+39 added−51 removed

modified:src/benchmark/benchmark_result.rs+12 added-28 removed
1 unmodified line
23use serde::Serialize;4use statistical::{mean, median, standard_deviation};56use crate::{7 outlier_detection::modified_zscores,6use crate::util::{7 min_max::{max, min},8 units::Second,8 util::{9 min_max::{max, min},10 units::Second,11 },12};1314/// Performance metrics and exit codes for each run15#[derive(Debug, Default, Clone, Serialize, PartialEq)]
92 unmodified lines
108 .map(|run| run.system_time)109 .collect::<Vec<_>>(),110 )111 }112113 pub fn modified_zscores(&self) -> Vec<f64> {114 modified_zscores(&self.wall_clock_times())115 }116}117118/// Parameter value and whether it was used in the command line template119#[derive(Debug, Default, Clone, Serialize, PartialEq)]
26 unmodified lines
146 pub parameters: BTreeMap<String, Parameter>,147}148149impl BenchmarkResult {150 /// The average wall clock time143 pub fn mean(&self) -> Second {151 pub fn mean_wall_clock_time(&self) -> Second {152 self.runs.mean()153 }154147 pub fn stddev(&self) -> Option<Second> {148 self.runs.stddev()149 }150151 pub fn median(&self) -> Second {152 self.runs.median()153 }154155 pub fn min(&self) -> Second {156 self.runs.min()157 }158159 pub fn max(&self) -> Second {160 self.runs.max()161 }162163 pub fn user_mean(&self) -> Second {164 self.runs.user_mean()165 }166167 pub fn system_mean(&self) -> Second {168 self.runs.system_mean()169 }170155 /// The full command line of the program that is being benchmarked, possibly including a list of156 /// parameters that were not used in the command line template.157 pub fn command_with_unused_parameters(&self) -> String {158 let parameters = self
16 unmodified lines
modified:src/benchmark/mod.rs+2 added-1 removed
13 unmodified lines
14use crate::options::{15 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,16};17use crate::outlier_detection::OUTLIER_THRESHOLD;18use crate::output::format::{format_duration, format_duration_unit};19use crate::output::console_writeln;20use crate::output::progress_bar::{21 finish_initial_measurement, get_progress_bar, start_initial_measurement,22};
418 unmodified lines
441 warnings.push(Warnings::NonZeroExitCode);442 }443444 // Run outlier detection444 let scores = modified_zscores(&runs.wall_clock_times());445 let scores = runs.modified_zscores();446447 let outlier_warning_options = OutlierWarningOptions {448 warmup_in_use: self.options.warmup_count > 0,449 prepare_in_use: self
52 unmodified lines
modified:src/benchmark/relative_speed.rs+10 added-5 removed
29 unmodified lines
30 }31}3233pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {34 l.mean().partial_cmp(&r.mean()).unwrap_or(Ordering::Equal)34 l.mean_wall_clock_time()35 .partial_cmp(&r.mean_wall_clock_time())36 .unwrap_or(Ordering::Equal)37}3839pub fn fastest_of(results: &[BenchmarkResult]) -> &BenchmarkResult {40 results
26 unmodified lines
67 };68 }6970 let ratio = match relative_ordering {69 Ordering::Less => reference.mean() / result.mean(),71 Ordering::Less => reference.mean_wall_clock_time() / result.mean_wall_clock_time(),72 Ordering::Equal => 1.0,71 Ordering::Greater => result.mean() / reference.mean(),73 Ordering::Greater => {74 result.mean_wall_clock_time() / reference.mean_wall_clock_time()75 }76 };7778 // https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas79 // Covariance assumed to be 0, i.e. variables are assumed to be independent
36 unmodified lines
116 results: &'a [BenchmarkResult],117 reference: &'a BenchmarkResult,118 sort_order: SortOrder,119) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'a>>> {116 if fastest_of(results).mean() == 0.0 || reference.mean() == 0.0 {120 if fastest_of(results).mean_wall_clock_time() == 0.0 || reference.mean_wall_clock_time() == 0.0121 {122 return None;123 }124125 Some(compute_relative_speeds(results, reference, sort_order))
4 unmodified lines
130 sort_order: SortOrder,131) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'_>>> {132 let fastest = fastest_of(results);133129 if fastest.mean() == 0.0 {134 if fastest.mean_wall_clock_time() == 0.0 {135 return None;136 }137138 Some(compute_relative_speeds(results, fastest, sort_order))
97 unmodified lines
modified:src/export/csv.rs+7 added-7 removed
42 unmodified lines
4344 for res in results {45 let mut fields = vec![Cow::Borrowed(res.command.as_bytes())];46 for f in &[47 res.mean(),48 res.stddev().unwrap_or(0.0),49 res.median(),50 res.user_mean(),51 res.system_mean(),52 res.min(),53 res.max(),47 res.mean_wall_clock_time(),48 res.runs.stddev().unwrap_or(0.0),49 res.runs.median(),50 res.runs.user_mean(),51 res.runs.system_mean(),52 res.runs.min(),53 res.runs.max(),54 ] {55 fields.push(Cow::Owned(56 f.format_with_precision(CSV_UNIT, CSV_PRECISION)57 .into_bytes(),
130 unmodified lines
modified:src/export/markup.rs+8 added-10 removed
46 unmodified lines
47 // emit horizontal line48 table.push_str(&self.table_divider(&cells_alignment));4950 for entry in entries {51 let measurement = &entry.result;51 let result = &entry.result;52 // prepare data row strings53 let cmd_str = measurement54 .command_with_unused_parameters()55 .replace('|', "\\|");56 let mean_str = format_duration_value(measurement.mean(), Some(unit)).0;57 let stddev_str = if let Some(stddev) = measurement.stddev() {53 let cmd_str = result.command_with_unused_parameters().replace('|', "\\|");54 let mean_str = format_duration_value(result.mean_wall_clock_time(), Some(unit)).0;55 let stddev_str = if let Some(stddev) = result.runs.stddev() {56 format!(" ± {}", format_duration_value(stddev, Some(unit)).0)57 } else {58 "".into()59 };62 let min_str = measurement.measurements.min().format_value(unit);63 let max_str = measurement.measurements.max().format_value(unit);60 let min_str = result.measurements.min().format_value(unit);61 let max_str = result.measurements.max().format_value(unit);62 // The ratio of two zero times is undefined, even if they compare equal.63 let relative_unavailable = reference_pending64 || (explicit_reference65 && !entry.is_reference66 && entry.relative_ordering == Ordering::Equal69 && measurement.mean_wall_clock_time() == Time::zero());67 && result.mean_wall_clock_time() == Time::zero());68 let relative = if relative_unavailable {69 "N/A".to_string()70 } else {71 let stddev = match (entry.is_reference, entry.relative_speed_stddev) {
41 unmodified lines
113114fn determine_unit_from_results(results: &[BenchmarkResult]) -> TimeUnit {115 if let Some(first_result) = results.first() {116 // Use the first BenchmarkResult entry to determine the unit for all entries.119 format_duration_value(first_result.mean(), None).1117 format_duration_value(first_result.mean_wall_clock_time(), None).1118 } else {119 // Default to `Second`.120 TimeUnit::Second121 }
25 unmodified lines