mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-31 16:40:18 +00:00
Move Options struct to new module
This commit is contained in:
1 parent
eee32308b7
commit
465160b9aa
6 files changed
+112
-108
No files matched your search
@@ -8,13 +8,12 @@ use statistical::{mean, median, standard_deviation};
|
||||
use crate::hyperfine::command::Command;
|
||||
use crate::hyperfine::format::{format_duration, format_duration_unit};
|
||||
use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};
|
||||
use crate::hyperfine::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};
|
||||
use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};
|
||||
use crate::hyperfine::shell::execute_and_time;
|
||||
use crate::hyperfine::timer::wallclocktimer::WallClockTimer;
|
||||
use crate::hyperfine::timer::{TimerStart, TimerStop};
|
||||
use crate::hyperfine::types::{
|
||||
BenchmarkResult, CmdFailureAction, HyperfineOptions, OutputStyleOption,
|
||||
};
|
||||
use crate::hyperfine::types::BenchmarkResult;
|
||||
use crate::hyperfine::units::Second;
|
||||
use crate::hyperfine::warnings::Warnings;
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use colored::*;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
|
||||
use crate::hyperfine::types::{BenchmarkResult, OutputStyleOption};
|
||||
use crate::hyperfine::options::OutputStyleOption;
|
||||
use crate::hyperfine::types::BenchmarkResult;
|
||||
use crate::hyperfine::units::{Scalar, Second};
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
@@ -5,6 +5,7 @@ pub mod error;
|
||||
pub mod export;
|
||||
pub mod format;
|
||||
pub mod internal;
|
||||
pub mod options;
|
||||
pub mod outlier_detection;
|
||||
pub mod parameter_range;
|
||||
pub mod shell;
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
use super::{
|
||||
types::DEFAULT_SHELL,
|
||||
units::{Second, Unit},
|
||||
};
|
||||
|
||||
/// Action to take when an executed command fails.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum CmdFailureAction {
|
||||
/// Exit with an error message
|
||||
RaiseError,
|
||||
|
||||
/// Simply ignore the non-zero exit code
|
||||
Ignore,
|
||||
}
|
||||
|
||||
/// Output style type option
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum OutputStyleOption {
|
||||
/// Do not output with colors or any special formatting
|
||||
Basic,
|
||||
|
||||
/// Output with full color and formatting
|
||||
Full,
|
||||
|
||||
/// Keep elements such as progress bar, but use no coloring
|
||||
NoColor,
|
||||
|
||||
/// Keep coloring, but use no progress bar
|
||||
Color,
|
||||
|
||||
/// Disable all the output
|
||||
Disabled,
|
||||
}
|
||||
|
||||
/// Number of runs for a benchmark
|
||||
pub struct Runs {
|
||||
/// Minimum number of benchmark runs
|
||||
pub min: u64,
|
||||
|
||||
/// Maximum number of benchmark runs
|
||||
pub max: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for Runs {
|
||||
fn default() -> Runs {
|
||||
Runs { min: 10, max: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of options for hyperfine
|
||||
pub struct HyperfineOptions {
|
||||
/// Number of warmup runs
|
||||
pub warmup_count: u64,
|
||||
|
||||
/// Number of benchmark runs
|
||||
pub runs: Runs,
|
||||
|
||||
/// Minimum benchmarking time
|
||||
pub min_time_sec: Second,
|
||||
|
||||
/// Whether or not to ignore non-zero exit codes
|
||||
pub failure_action: CmdFailureAction,
|
||||
|
||||
/// Command to run before each timing run
|
||||
pub preparation_command: Option<Vec<String>>,
|
||||
|
||||
/// Command to run after each benchmark
|
||||
pub cleanup_command: Option<String>,
|
||||
|
||||
/// What color mode to use for output
|
||||
pub output_style: OutputStyleOption,
|
||||
|
||||
/// The shell to use for executing commands.
|
||||
pub shell: String,
|
||||
|
||||
/// Forward benchmark's stdout to hyperfine's stdout
|
||||
pub show_output: bool,
|
||||
|
||||
/// Which time unit to use for CLI & Markdown output
|
||||
pub time_unit: Option<Unit>,
|
||||
|
||||
/// A list of custom command names that, if defined,
|
||||
/// will be used instead of the command itself in
|
||||
/// benchmark outputs.
|
||||
pub names: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl Default for HyperfineOptions {
|
||||
fn default() -> HyperfineOptions {
|
||||
HyperfineOptions {
|
||||
names: None,
|
||||
warmup_count: 0,
|
||||
runs: Runs::default(),
|
||||
min_time_sec: 3.0,
|
||||
failure_action: CmdFailureAction::RaiseError,
|
||||
preparation_command: None,
|
||||
cleanup_command: None,
|
||||
output_style: OutputStyleOption::Full,
|
||||
shell: DEFAULT_SHELL.to_string(),
|
||||
show_output: false,
|
||||
time_unit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-101
@@ -6,7 +6,7 @@ use std::fmt;
|
||||
use rust_decimal::prelude::ToPrimitive;
|
||||
use rust_decimal::Decimal;
|
||||
|
||||
use crate::hyperfine::units::{Second, Unit};
|
||||
use crate::hyperfine::units::Second;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub const DEFAULT_SHELL: &str = "sh";
|
||||
@@ -71,106 +71,6 @@ impl<'a> ToString for ParameterValue {
|
||||
}
|
||||
}
|
||||
|
||||
/// Action to take when an executed command fails.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum CmdFailureAction {
|
||||
/// Exit with an error message
|
||||
RaiseError,
|
||||
|
||||
/// Simply ignore the non-zero exit code
|
||||
Ignore,
|
||||
}
|
||||
|
||||
/// Output style type option
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum OutputStyleOption {
|
||||
/// Do not output with colors or any special formatting
|
||||
Basic,
|
||||
|
||||
/// Output with full color and formatting
|
||||
Full,
|
||||
|
||||
/// Keep elements such as progress bar, but use no coloring
|
||||
NoColor,
|
||||
|
||||
/// Keep coloring, but use no progress bar
|
||||
Color,
|
||||
|
||||
/// Disable all the output
|
||||
Disabled,
|
||||
}
|
||||
|
||||
/// Number of runs for a benchmark
|
||||
pub struct Runs {
|
||||
/// Minimum number of benchmark runs
|
||||
pub min: u64,
|
||||
|
||||
/// Maximum number of benchmark runs
|
||||
pub max: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for Runs {
|
||||
fn default() -> Runs {
|
||||
Runs { min: 10, max: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of options for hyperfine
|
||||
pub struct HyperfineOptions {
|
||||
/// Number of warmup runs
|
||||
pub warmup_count: u64,
|
||||
|
||||
/// Number of benchmark runs
|
||||
pub runs: Runs,
|
||||
|
||||
/// Minimum benchmarking time
|
||||
pub min_time_sec: Second,
|
||||
|
||||
/// Whether or not to ignore non-zero exit codes
|
||||
pub failure_action: CmdFailureAction,
|
||||
|
||||
/// Command to run before each timing run
|
||||
pub preparation_command: Option<Vec<String>>,
|
||||
|
||||
/// Command to run after each benchmark
|
||||
pub cleanup_command: Option<String>,
|
||||
|
||||
/// What color mode to use for output
|
||||
pub output_style: OutputStyleOption,
|
||||
|
||||
/// The shell to use for executing commands.
|
||||
pub shell: String,
|
||||
|
||||
/// Forward benchmark's stdout to hyperfine's stdout
|
||||
pub show_output: bool,
|
||||
|
||||
/// Which time unit to use for CLI & Markdown output
|
||||
pub time_unit: Option<Unit>,
|
||||
|
||||
/// A list of custom command names that, if defined,
|
||||
/// will be used instead of the command itself in
|
||||
/// benchmark outputs.
|
||||
pub names: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl Default for HyperfineOptions {
|
||||
fn default() -> HyperfineOptions {
|
||||
HyperfineOptions {
|
||||
names: None,
|
||||
warmup_count: 0,
|
||||
runs: Runs::default(),
|
||||
min_time_sec: 3.0,
|
||||
failure_action: CmdFailureAction::RaiseError,
|
||||
preparation_command: None,
|
||||
cleanup_command: None,
|
||||
output_style: OutputStyleOption::Full,
|
||||
shell: DEFAULT_SHELL.to_string(),
|
||||
show_output: false,
|
||||
time_unit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set of values that will be exported.
|
||||
// NOTE: `serde` is used for JSON serialization, but not for CSV serialization due to the
|
||||
// `parameters` map. Update `src/hyperfine/export/csv.rs` with new fields, as appropriate.
|
||||
|
||||
+2
-3
@@ -15,10 +15,9 @@ use crate::hyperfine::command::Command;
|
||||
use crate::hyperfine::error::OptionsError;
|
||||
use crate::hyperfine::export::{ExportManager, ExportType};
|
||||
use crate::hyperfine::internal::{tokenize, write_benchmark_comparison};
|
||||
use crate::hyperfine::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};
|
||||
use crate::hyperfine::parameter_range::get_parameterized_commands;
|
||||
use crate::hyperfine::types::{
|
||||
CmdFailureAction, HyperfineOptions, OutputStyleOption, ParameterValue,
|
||||
};
|
||||
use crate::hyperfine::types::ParameterValue;
|
||||
use crate::hyperfine::units::Unit;
|
||||
|
||||
/// Print error message to stderr and terminate
|
||||
|
||||
Reference in new issue
Block a user