Skip to content
Myr

Move Options struct to new module

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 eee3230 · Browse files · 6 files+112 added−108 removed
This commit

State

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

Diff stats

6 files+112 added−108 removed

  • other:+112 added−108 removed

6 files+112 added−108 removed

modified:src/hyperfine/benchmark.rs+2 added-3 removed
6 unmodified lines
78use crate::hyperfine::command::Command;9use crate::hyperfine::format::{format_duration, format_duration_unit};10use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};11use crate::hyperfine::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};12use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};13use crate::hyperfine::shell::execute_and_time;14use crate::hyperfine::timer::wallclocktimer::WallClockTimer;15use crate::hyperfine::timer::{TimerStart, TimerStop};15use crate::hyperfine::types::{16 BenchmarkResult, CmdFailureAction, HyperfineOptions, OutputStyleOption,17};16use crate::hyperfine::types::BenchmarkResult;17use crate::hyperfine::units::Second;18use crate::hyperfine::warnings::Warnings;1920/// Results from timing a single shell command
464 unmodified lines
modified:src/hyperfine/internal.rs+2 added-1 removed
1use colored::*;2use indicatif::{ProgressBar, ProgressStyle};34use crate::hyperfine::types::{BenchmarkResult, OutputStyleOption};4use crate::hyperfine::options::OutputStyleOption;5use crate::hyperfine::types::BenchmarkResult;6use crate::hyperfine::units::{Scalar, Second};78use std::cmp::Ordering;9use std::iter::Iterator;
246 unmodified lines
modified:src/hyperfine/mod.rs+1 added
3 unmodified lines
4pub mod error;5pub mod export;6pub mod format;7pub mod internal;8pub mod options;9pub mod outlier_detection;10pub mod parameter_range;11pub mod shell;12pub mod timer;
3 unmodified lines
added:src/hyperfine/options.rs+104 added
1use super::{2 types::DEFAULT_SHELL,3 units::{Second, Unit},4};56/// Action to take when an executed command fails.7#[derive(Debug, Clone, Copy, PartialEq)]8pub enum CmdFailureAction {9 /// Exit with an error message10 RaiseError,1112 /// Simply ignore the non-zero exit code13 Ignore,14}1516/// Output style type option17#[derive(Debug, Clone, Copy, PartialEq)]18pub enum OutputStyleOption {19 /// Do not output with colors or any special formatting20 Basic,2122 /// Output with full color and formatting23 Full,2425 /// Keep elements such as progress bar, but use no coloring26 NoColor,2728 /// Keep coloring, but use no progress bar29 Color,3031 /// Disable all the output32 Disabled,33}3435/// Number of runs for a benchmark36pub struct Runs {37 /// Minimum number of benchmark runs38 pub min: u64,3940 /// Maximum number of benchmark runs41 pub max: Option<u64>,42}4344impl Default for Runs {45 fn default() -> Runs {46 Runs { min: 10, max: None }47 }48}4950/// A set of options for hyperfine51pub struct HyperfineOptions {52 /// Number of warmup runs53 pub warmup_count: u64,5455 /// Number of benchmark runs56 pub runs: Runs,5758 /// Minimum benchmarking time59 pub min_time_sec: Second,6061 /// Whether or not to ignore non-zero exit codes62 pub failure_action: CmdFailureAction,6364 /// Command to run before each timing run65 pub preparation_command: Option<Vec<String>>,6667 /// Command to run after each benchmark68 pub cleanup_command: Option<String>,6970 /// What color mode to use for output71 pub output_style: OutputStyleOption,7273 /// The shell to use for executing commands.74 pub shell: String,7576 /// Forward benchmark's stdout to hyperfine's stdout77 pub show_output: bool,7879 /// Which time unit to use for CLI & Markdown output80 pub time_unit: Option<Unit>,8182 /// A list of custom command names that, if defined,83 /// will be used instead of the command itself in84 /// benchmark outputs.85 pub names: Option<Vec<String>>,86}8788impl Default for HyperfineOptions {89 fn default() -> HyperfineOptions {90 HyperfineOptions {91 names: None,92 warmup_count: 0,93 runs: Runs::default(),94 min_time_sec: 3.0,95 failure_action: CmdFailureAction::RaiseError,96 preparation_command: None,97 cleanup_command: None,98 output_style: OutputStyleOption::Full,99 shell: DEFAULT_SHELL.to_string(),100 show_output: false,101 time_unit: None,102 }103 }104}
modified:src/hyperfine/types.rs+1 added-101 removed
4 unmodified lines
56use rust_decimal::prelude::ToPrimitive;7use rust_decimal::Decimal;89use crate::hyperfine::units::{Second, Unit};9use crate::hyperfine::units::Second;1011#[cfg(not(windows))]12pub const DEFAULT_SHELL: &str = "sh";13
56 unmodified lines
70 }71 }72}7374/// Action to take when an executed command fails.75#[derive(Debug, Clone, Copy, PartialEq)]76pub enum CmdFailureAction {77 /// Exit with an error message78 RaiseError,7980 /// Simply ignore the non-zero exit code81 Ignore,82}8384/// Output style type option85#[derive(Debug, Clone, Copy, PartialEq)]86pub enum OutputStyleOption {87 /// Do not output with colors or any special formatting88 Basic,8990 /// Output with full color and formatting91 Full,9293 /// Keep elements such as progress bar, but use no coloring94 NoColor,9596 /// Keep coloring, but use no progress bar97 Color,9899 /// Disable all the output100 Disabled,101}102103/// Number of runs for a benchmark104pub struct Runs {105 /// Minimum number of benchmark runs106 pub min: u64,107108 /// Maximum number of benchmark runs109 pub max: Option<u64>,110}111112impl Default for Runs {113 fn default() -> Runs {114 Runs { min: 10, max: None }115 }116}117118/// A set of options for hyperfine119pub struct HyperfineOptions {120 /// Number of warmup runs121 pub warmup_count: u64,122123 /// Number of benchmark runs124 pub runs: Runs,125126 /// Minimum benchmarking time127 pub min_time_sec: Second,128129 /// Whether or not to ignore non-zero exit codes130 pub failure_action: CmdFailureAction,131132 /// Command to run before each timing run133 pub preparation_command: Option<Vec<String>>,134135 /// Command to run after each benchmark136 pub cleanup_command: Option<String>,137138 /// What color mode to use for output139 pub output_style: OutputStyleOption,140141 /// The shell to use for executing commands.142 pub shell: String,143144 /// Forward benchmark's stdout to hyperfine's stdout145 pub show_output: bool,146147 /// Which time unit to use for CLI & Markdown output148 pub time_unit: Option<Unit>,149150 /// A list of custom command names that, if defined,151 /// will be used instead of the command itself in152 /// benchmark outputs.153 pub names: Option<Vec<String>>,154}155156impl Default for HyperfineOptions {157 fn default() -> HyperfineOptions {158 HyperfineOptions {159 names: None,160 warmup_count: 0,161 runs: Runs::default(),162 min_time_sec: 3.0,163 failure_action: CmdFailureAction::RaiseError,164 preparation_command: None,165 cleanup_command: None,166 output_style: OutputStyleOption::Full,167 shell: DEFAULT_SHELL.to_string(),168 show_output: false,169 time_unit: None,170 }171 }172}17374/// Set of values that will be exported.75// NOTE: `serde` is used for JSON serialization, but not for CSV serialization due to the76// `parameters` map. Update `src/hyperfine/export/csv.rs` with new fields, as appropriate.77#[derive(Debug, Default, Clone, Serialize, PartialEq)]
68 unmodified lines
modified:src/main.rs+2 added-3 removed
13 unmodified lines
14use crate::hyperfine::command::Command;15use crate::hyperfine::error::OptionsError;16use crate::hyperfine::export::{ExportManager, ExportType};17use crate::hyperfine::internal::{tokenize, write_benchmark_comparison};18use crate::hyperfine::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};19use crate::hyperfine::parameter_range::get_parameterized_commands;19use crate::hyperfine::types::{20 CmdFailureAction, HyperfineOptions, OutputStyleOption, ParameterValue,21};20use crate::hyperfine::types::ParameterValue;21use crate::hyperfine::units::Unit;2223/// Print error message to stderr and terminate24pub fn error(message: &str) -> ! {
383 unmodified lines