Skip to content
Myr

Move more modules around

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 47091a5 · Browse files · 10 files+158 added−158 removed
This commit

State

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

Diff stats

10 files+158 added−158 removed

  • other:+158 added−158 removed

10 files+158 added−158 removed

modified:src/benchmark/mod.rs+1 added
1pub mod relative_speed;2pub mod result;34use std::cmp;5use std::process::{ExitStatus, Stdio};
514 unmodified lines
added:src/benchmark/relative_speed.rs+100 added
1use std::cmp::Ordering;23use super::result::BenchmarkResult;4use crate::units::Scalar;56#[derive(Debug)]7pub struct BenchmarkResultWithRelativeSpeed<'a> {8 pub result: &'a BenchmarkResult,9 pub relative_speed: Scalar,10 pub relative_speed_stddev: Option<Scalar>,11 pub is_fastest: bool,12}1314pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {15 l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal)16}1718pub fn compute(results: &[BenchmarkResult]) -> Option<Vec<BenchmarkResultWithRelativeSpeed>> {19 let fastest: &BenchmarkResult = results20 .iter()21 .min_by(|&l, &r| compare_mean_time(l, r))22 .expect("at least one benchmark result");2324 if fastest.mean == 0.0 {25 return None;26 }2728 Some(29 results30 .iter()31 .map(|result| {32 let ratio = result.mean / fastest.mean;3334 // https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas35 // Covariance asssumed to be 0, i.e. variables are assumed to be independent36 let ratio_stddev = match (result.stddev, fastest.stddev) {37 (Some(result_stddev), Some(fastest_stddev)) => Some(38 ratio39 * ((result_stddev / result.mean).powi(2)40 + (fastest_stddev / fastest.mean).powi(2))41 .sqrt(),42 ),43 _ => None,44 };4546 BenchmarkResultWithRelativeSpeed {47 result,48 relative_speed: ratio,49 relative_speed_stddev: ratio_stddev,50 is_fastest: result == fastest,51 }52 })53 .collect(),54 )55}5657#[cfg(test)]58fn create_result(name: &str, mean: Scalar) -> BenchmarkResult {59 use std::collections::BTreeMap;6061 BenchmarkResult {62 command: name.into(),63 mean,64 stddev: Some(1.0),65 median: mean,66 user: mean,67 system: 0.0,68 min: mean,69 max: mean,70 times: None,71 exit_codes: Vec::new(),72 parameters: BTreeMap::new(),73 }74}7576#[test]77fn test_compute_relative_speed() {78 use approx::assert_relative_eq;7980 let results = vec![81 create_result("cmd1", 3.0),82 create_result("cmd2", 2.0),83 create_result("cmd3", 5.0),84 ];8586 let annotated_results = compute(&results).unwrap();8788 assert_relative_eq!(1.5, annotated_results[0].relative_speed);89 assert_relative_eq!(1.0, annotated_results[1].relative_speed);90 assert_relative_eq!(2.5, annotated_results[2].relative_speed);91}9293#[test]94fn test_compute_relative_speed_for_zero_times() {95 let results = vec![create_result("cmd1", 1.0), create_result("cmd2", 0.0)];9697 let annotated_results = compute(&results);9899 assert!(annotated_results.is_none());100}
modified:src/export/asciidoc.rs+1 added-1 removed
1use crate::benchmark::relative_speed::{self, BenchmarkResultWithRelativeSpeed};2use crate::benchmark::result::BenchmarkResult;3use crate::output::format::format_duration_value;3use crate::relative_speed::{self, BenchmarkResultWithRelativeSpeed};4use crate::units::Unit;56use super::Exporter;7
266 unmodified lines
modified:src/export/markdown.rs+1 added-1 removed
1use super::Exporter;2use crate::benchmark::relative_speed::{self, BenchmarkResultWithRelativeSpeed};3use crate::benchmark::result::BenchmarkResult;4use crate::output::format::format_duration_value;4use crate::relative_speed::{self, BenchmarkResultWithRelativeSpeed};5use crate::units::Unit;67use anyhow::{anyhow, Result};8
285 unmodified lines
modified:src/parameter/mod.rs+2 added-2 removed
1use crate::numeric::NumericType;1use crate::number::Number;23pub mod range;4pub mod tokenize;56#[derive(Debug, Clone, PartialEq, Eq)]7pub enum ParameterValue {8 Text(String),9 Numeric(NumericType),9 Numeric(Number),10}1112impl<'a> ToString for ParameterValue {13 fn to_string(&self) -> String {
6 unmodified lines
modified:src/parameter/range.rs+3 added-3 removed
6 unmodified lines
78use super::ParameterValue;9use crate::command::Command;10use crate::error::ParameterScanError;11use crate::numeric::NumericType;11use crate::number::Number;1213trait Numeric:14 Add<Output = Self>15 + Sub<Output = Self>
2 unmodified lines
18 + PartialOrd19 + Copy20 + Clone21 + From<i32>22 + Into<NumericType>22 + Into<Number>23{24}25impl<26 T: Add<Output = Self>
3 unmodified lines
30 + PartialOrd31 + Copy32 + Clone33 + From<i32>34 + Into<NumericType>,34 + Into<Number>,35 > Numeric for T36{37}38
280 unmodified lines
modified:src/main.rs+2 added-3 removed
1use std::env;23use app::get_arg_matches;4use benchmark::result::BenchmarkResult;5use benchmark::{mean_shell_spawning_time, run_benchmark};5use benchmark::{mean_shell_spawning_time, relative_speed, run_benchmark};6use command::{build_commands, Command};7use export::ExportManager;8use options::{Options, OutputStyleOption};9
5 unmodified lines
15pub mod command;16pub mod error;17pub mod export;18pub mod min_max;19pub mod numeric;19pub mod number;20pub mod options;21pub mod outlier_detection;22pub mod output;23pub mod parameter;24pub mod relative_speed;24pub mod shell;25pub mod timer;26pub mod units;27
95 unmodified lines
added:src/number.rs+48 added
1use std::convert::TryFrom;2use std::fmt;34use rust_decimal::prelude::ToPrimitive;5use rust_decimal::Decimal;6use serde::Serialize;78#[derive(Debug, Clone, Serialize, Copy, PartialEq, Eq)]9#[serde(untagged)]10pub enum Number {11 Int(i32),12 Decimal(Decimal),13}1415impl fmt::Display for Number {16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {17 match *self {18 Number::Int(i) => fmt::Display::fmt(&i, f),19 Number::Decimal(i) => fmt::Display::fmt(&i, f),20 }21 }22}2324impl From<i32> for Number {25 fn from(x: i32) -> Number {26 Number::Int(x)27 }28}2930impl From<Decimal> for Number {31 fn from(x: Decimal) -> Number {32 Number::Decimal(x)33 }34}3536impl TryFrom<Number> for usize {37 type Error = ();3839 fn try_from(numeric: Number) -> Result<Self, Self::Error> {40 match numeric {41 Number::Int(i) => usize::try_from(i).map_err(|_| ()),42 Number::Decimal(d) => match d.to_u64() {43 Some(u) => usize::try_from(u).map_err(|_| ()),44 None => Err(()),45 },46 }47 }48}
deleted:src/numeric.rs-48 removed
1use std::convert::TryFrom;2use std::fmt;34use rust_decimal::prelude::ToPrimitive;5use rust_decimal::Decimal;6use serde::Serialize;78#[derive(Debug, Clone, Serialize, Copy, PartialEq, Eq)]9#[serde(untagged)]10pub enum NumericType {11 Int(i32),12 Decimal(Decimal),13}1415impl fmt::Display for NumericType {16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {17 match *self {18 NumericType::Int(i) => fmt::Display::fmt(&i, f),19 NumericType::Decimal(i) => fmt::Display::fmt(&i, f),20 }21 }22}2324impl From<i32> for NumericType {25 fn from(x: i32) -> NumericType {26 NumericType::Int(x)27 }28}2930impl From<Decimal> for NumericType {31 fn from(x: Decimal) -> NumericType {32 NumericType::Decimal(x)33 }34}3536impl TryFrom<NumericType> for usize {37 type Error = ();3839 fn try_from(numeric: NumericType) -> Result<Self, Self::Error> {40 match numeric {41 NumericType::Int(i) => usize::try_from(i).map_err(|_| ()),42 NumericType::Decimal(d) => match d.to_u64() {43 Some(u) => usize::try_from(u).map_err(|_| ()),44 None => Err(()),45 },46 }47 }48}
deleted:src/relative_speed.rs-100 removed
1use std::cmp::Ordering;23use crate::benchmark::result::BenchmarkResult;4use crate::units::Scalar;56#[derive(Debug)]7pub struct BenchmarkResultWithRelativeSpeed<'a> {8 pub result: &'a BenchmarkResult,9 pub relative_speed: Scalar,10 pub relative_speed_stddev: Option<Scalar>,11 pub is_fastest: bool,12}1314pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {15 l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal)16}1718pub fn compute(results: &[BenchmarkResult]) -> Option<Vec<BenchmarkResultWithRelativeSpeed>> {19 let fastest: &BenchmarkResult = results20 .iter()21 .min_by(|&l, &r| compare_mean_time(l, r))22 .expect("at least one benchmark result");2324 if fastest.mean == 0.0 {25 return None;26 }2728 Some(29 results30 .iter()31 .map(|result| {32 let ratio = result.mean / fastest.mean;3334 // https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas35 // Covariance asssumed to be 0, i.e. variables are assumed to be independent36 let ratio_stddev = match (result.stddev, fastest.stddev) {37 (Some(result_stddev), Some(fastest_stddev)) => Some(38 ratio39 * ((result_stddev / result.mean).powi(2)40 + (fastest_stddev / fastest.mean).powi(2))41 .sqrt(),42 ),43 _ => None,44 };4546 BenchmarkResultWithRelativeSpeed {47 result,48 relative_speed: ratio,49 relative_speed_stddev: ratio_stddev,50 is_fastest: result == fastest,51 }52 })53 .collect(),54 )55}5657#[cfg(test)]58fn create_result(name: &str, mean: Scalar) -> BenchmarkResult {59 use std::collections::BTreeMap;6061 BenchmarkResult {62 command: name.into(),63 mean,64 stddev: Some(1.0),65 median: mean,66 user: mean,67 system: 0.0,68 min: mean,69 max: mean,70 times: None,71 exit_codes: Vec::new(),72 parameters: BTreeMap::new(),73 }74}7576#[test]77fn test_compute_relative_speed() {78 use approx::assert_relative_eq;7980 let results = vec![81 create_result("cmd1", 3.0),82 create_result("cmd2", 2.0),83 create_result("cmd3", 5.0),84 ];8586 let annotated_results = compute(&results).unwrap();8788 assert_relative_eq!(1.5, annotated_results[0].relative_speed);89 assert_relative_eq!(1.0, annotated_results[1].relative_speed);90 assert_relative_eq!(2.5, annotated_results[2].relative_speed);91}9293#[test]94fn test_compute_relative_speed_for_zero_times() {95 let results = vec![create_result("cmd1", 1.0), create_result("cmd2", 0.0)];9697 let annotated_results = compute(&results);9899 assert!(annotated_results.is_none());100}