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
Provenance
- Commit
465160b- Tree
4bc3392- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
eee3230
6 files changed+112 added−108 removed
modified:src/hyperfine/benchmark.rs+2 added-3 removed
6 unmodified lines7 8 use crate::hyperfine::command::Command;9 use crate::hyperfine::format::{format_duration, format_duration_unit};10 use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};11+use crate::hyperfine::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};12 use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};13 use crate::hyperfine::shell::execute_and_time;14 use crate::hyperfine::timer::wallclocktimer::WallClockTimer;15 use crate::hyperfine::timer::{TimerStart, TimerStop};15-use crate::hyperfine::types::{16- BenchmarkResult, CmdFailureAction, HyperfineOptions, OutputStyleOption,17-};16+use crate::hyperfine::types::BenchmarkResult;17 use crate::hyperfine::units::Second;18 use crate::hyperfine::warnings::Warnings;19 20 /// Results from timing a single shell command464 unmodified linesmodified:src/hyperfine/internal.rs+2 added-1 removed
1 use colored::*;2 use indicatif::{ProgressBar, ProgressStyle};3 4-use crate::hyperfine::types::{BenchmarkResult, OutputStyleOption};4+use crate::hyperfine::options::OutputStyleOption;5+use crate::hyperfine::types::BenchmarkResult;6 use crate::hyperfine::units::{Scalar, Second};7 8 use std::cmp::Ordering;9 use std::iter::Iterator;246 unmodified linesmodified:src/hyperfine/mod.rs+1 added
3 unmodified lines4 pub mod error;5 pub mod export;6 pub mod format;7 pub mod internal;8+pub mod options;9 pub mod outlier_detection;10 pub mod parameter_range;11 pub mod shell;12 pub mod timer;3 unmodified linesadded:src/hyperfine/options.rs+104 added
1+use super::{2+ types::DEFAULT_SHELL,3+ units::{Second, Unit},4+};5+6+/// Action to take when an executed command fails.7+#[derive(Debug, Clone, Copy, PartialEq)]8+pub enum CmdFailureAction {9+ /// Exit with an error message10+ RaiseError,11+12+ /// Simply ignore the non-zero exit code13+ Ignore,14+}15+16+/// Output style type option17+#[derive(Debug, Clone, Copy, PartialEq)]18+pub enum OutputStyleOption {19+ /// Do not output with colors or any special formatting20+ Basic,21+22+ /// Output with full color and formatting23+ Full,24+25+ /// Keep elements such as progress bar, but use no coloring26+ NoColor,27+28+ /// Keep coloring, but use no progress bar29+ Color,30+31+ /// Disable all the output32+ Disabled,33+}34+35+/// Number of runs for a benchmark36+pub struct Runs {37+ /// Minimum number of benchmark runs38+ pub min: u64,39+40+ /// Maximum number of benchmark runs41+ pub max: Option<u64>,42+}43+44+impl Default for Runs {45+ fn default() -> Runs {46+ Runs { min: 10, max: None }47+ }48+}49+50+/// A set of options for hyperfine51+pub struct HyperfineOptions {52+ /// Number of warmup runs53+ pub warmup_count: u64,54+55+ /// Number of benchmark runs56+ pub runs: Runs,57+58+ /// Minimum benchmarking time59+ pub min_time_sec: Second,60+61+ /// Whether or not to ignore non-zero exit codes62+ pub failure_action: CmdFailureAction,63+64+ /// Command to run before each timing run65+ pub preparation_command: Option<Vec<String>>,66+67+ /// Command to run after each benchmark68+ pub cleanup_command: Option<String>,69+70+ /// What color mode to use for output71+ pub output_style: OutputStyleOption,72+73+ /// The shell to use for executing commands.74+ pub shell: String,75+76+ /// Forward benchmark's stdout to hyperfine's stdout77+ pub show_output: bool,78+79+ /// Which time unit to use for CLI & Markdown output80+ pub time_unit: Option<Unit>,81+82+ /// 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+}87+88+impl 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 lines5 6 use rust_decimal::prelude::ToPrimitive;7 use rust_decimal::Decimal;8 9-use crate::hyperfine::units::{Second, Unit};9+use crate::hyperfine::units::Second;10 11 #[cfg(not(windows))]12 pub const DEFAULT_SHELL: &str = "sh";13 56 unmodified lines70 }71 }72 }73 74-/// Action to take when an executed command fails.75-#[derive(Debug, Clone, Copy, PartialEq)]76-pub enum CmdFailureAction {77- /// Exit with an error message78- RaiseError,79-80- /// Simply ignore the non-zero exit code81- Ignore,82-}83-84-/// Output style type option85-#[derive(Debug, Clone, Copy, PartialEq)]86-pub enum OutputStyleOption {87- /// Do not output with colors or any special formatting88- Basic,89-90- /// Output with full color and formatting91- Full,92-93- /// Keep elements such as progress bar, but use no coloring94- NoColor,95-96- /// Keep coloring, but use no progress bar97- Color,98-99- /// Disable all the output100- Disabled,101-}102-103-/// Number of runs for a benchmark104-pub struct Runs {105- /// Minimum number of benchmark runs106- pub min: u64,107-108- /// Maximum number of benchmark runs109- pub max: Option<u64>,110-}111-112-impl Default for Runs {113- fn default() -> Runs {114- Runs { min: 10, max: None }115- }116-}117-118-/// A set of options for hyperfine119-pub struct HyperfineOptions {120- /// Number of warmup runs121- pub warmup_count: u64,122-123- /// Number of benchmark runs124- pub runs: Runs,125-126- /// Minimum benchmarking time127- pub min_time_sec: Second,128-129- /// Whether or not to ignore non-zero exit codes130- pub failure_action: CmdFailureAction,131-132- /// Command to run before each timing run133- pub preparation_command: Option<Vec<String>>,134-135- /// Command to run after each benchmark136- pub cleanup_command: Option<String>,137-138- /// What color mode to use for output139- pub output_style: OutputStyleOption,140-141- /// The shell to use for executing commands.142- pub shell: String,143-144- /// Forward benchmark's stdout to hyperfine's stdout145- pub show_output: bool,146-147- /// Which time unit to use for CLI & Markdown output148- pub time_unit: Option<Unit>,149-150- /// 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-}155-156-impl 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-}173-74 /// 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 linesmodified:src/main.rs+2 added-3 removed
13 unmodified lines14 use crate::hyperfine::command::Command;15 use crate::hyperfine::error::OptionsError;16 use crate::hyperfine::export::{ExportManager, ExportType};17 use crate::hyperfine::internal::{tokenize, write_benchmark_comparison};18+use crate::hyperfine::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};19 use crate::hyperfine::parameter_range::get_parameterized_commands;19-use crate::hyperfine::types::{20- CmdFailureAction, HyperfineOptions, OutputStyleOption, ParameterValue,21-};20+use crate::hyperfine::types::ParameterValue;21 use crate::hyperfine::units::Unit;22 23 /// Print error message to stderr and terminate24 pub fn error(message: &str) -> ! {383 unmodified lines