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
Provenance
- Commit
8ba632c- Tree
3591758- Author
David Peter <sharkdp@users.noreply.github.com>- Committer
David Peter <mail@david-peter.de>- Parent
f7e6d72
5 files changed+39 added−51 removed
modified:src/benchmark/benchmark_result.rs+12 added-28 removed
1 unmodified line2 3 use serde::Serialize;4 use statistical::{mean, median, standard_deviation};5 6+use crate::{7+ outlier_detection::modified_zscores,6-use crate::util::{7- min_max::{max, min},8- units::Second,8+ util::{9+ min_max::{max, min},10+ units::Second,11+ },12 };13 14 /// Performance metrics and exit codes for each run15 #[derive(Debug, Default, Clone, Serialize, PartialEq)]92 unmodified lines108 .map(|run| run.system_time)109 .collect::<Vec<_>>(),110 )111 }112+113+ pub fn modified_zscores(&self) -> Vec<f64> {114+ modified_zscores(&self.wall_clock_times())115+ }116 }117 118 /// Parameter value and whether it was used in the command line template119 #[derive(Debug, Default, Clone, Serialize, PartialEq)]26 unmodified lines146 pub parameters: BTreeMap<String, Parameter>,147 }148 149 impl 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 }154 147- pub fn stddev(&self) -> Option<Second> {148- self.runs.stddev()149- }150-151- pub fn median(&self) -> Second {152- self.runs.median()153- }154-155- pub fn min(&self) -> Second {156- self.runs.min()157- }158-159- pub fn max(&self) -> Second {160- self.runs.max()161- }162-163- pub fn user_mean(&self) -> Second {164- self.runs.user_mean()165- }166-167- pub fn system_mean(&self) -> Second {168- self.runs.system_mean()169- }170-155 /// 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 = self16 unmodified linesmodified:src/benchmark/mod.rs+2 added-1 removed
13 unmodified lines14 use crate::options::{15 CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,16 };17 use crate::outlier_detection::OUTLIER_THRESHOLD;18+use crate::output::format::{format_duration, format_duration_unit};19 use crate::output::console_writeln;20 use crate::output::progress_bar::{21 finish_initial_measurement, get_progress_bar, start_initial_measurement,22 };418 unmodified lines441 warnings.push(Warnings::NonZeroExitCode);442 }443 444 // Run outlier detection444- let scores = modified_zscores(&runs.wall_clock_times());445+ let scores = runs.modified_zscores();446 447 let outlier_warning_options = OutlierWarningOptions {448 warmup_in_use: self.options.warmup_count > 0,449 prepare_in_use: self52 unmodified linesmodified:src/benchmark/relative_speed.rs+10 added-5 removed
29 unmodified lines30 }31 }32 33 pub 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 }38 39 pub fn fastest_of(results: &[BenchmarkResult]) -> &BenchmarkResult {40 results26 unmodified lines67 };68 }69 70 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 };77 78 // https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas79 // Covariance assumed to be 0, i.e. variables are assumed to be independent36 unmodified lines116 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 }124 125 Some(compute_relative_speeds(results, reference, sort_order))4 unmodified lines130 sort_order: SortOrder,131 ) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'_>>> {132 let fastest = fastest_of(results);133 129- if fastest.mean() == 0.0 {134+ if fastest.mean_wall_clock_time() == 0.0 {135 return None;136 }137 138 Some(compute_relative_speeds(results, fastest, sort_order))97 unmodified linesmodified:src/export/csv.rs+7 added-7 removed
42 unmodified lines43 44 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 linesmodified:src/export/markup.rs+8 added-10 removed
46 unmodified lines47 // emit horizontal line48 table.push_str(&self.table_divider(&cells_alignment));49 50 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 lines113 114 fn 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