mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 17:11:28 +00:00
Add comparison output when 2 or more commands are run
This also includes a restructure to the internal types used
This commit is contained in:
1 parent
8295327263
commit
3966bf05c1
15 files changed
+207
-150
No files matched your search
@@ -0,0 +1,116 @@
|
||||
/// The types module contains common internal types for the application.
|
||||
///
|
||||
|
||||
/// Type alias for unit of time
|
||||
pub type Second = f64;
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// A set of options for hyperfine
|
||||
pub struct HyperfineOptions {
|
||||
/// Number of warmup runs
|
||||
pub warmup_count: u64,
|
||||
|
||||
/// Minimum number of benchmark runs
|
||||
pub min_runs: u64,
|
||||
|
||||
/// 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<String>,
|
||||
|
||||
/// What color mode to use for output
|
||||
pub output_style: OutputStyleOption,
|
||||
}
|
||||
|
||||
impl Default for HyperfineOptions {
|
||||
fn default() -> HyperfineOptions {
|
||||
HyperfineOptions {
|
||||
warmup_count: 0,
|
||||
min_runs: 10,
|
||||
min_time_sec: 3.0,
|
||||
failure_action: CmdFailureAction::RaiseError,
|
||||
preparation_command: None,
|
||||
output_style: OutputStyleOption::Full,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set of values that will be exported.
|
||||
#[derive(Debug, Default, Clone, Serialize)]
|
||||
pub struct BenchmarkResult {
|
||||
/// The command that was run
|
||||
pub command: String,
|
||||
|
||||
/// The mean run time
|
||||
pub mean: Second,
|
||||
|
||||
/// The standard deviation of all run times
|
||||
pub stddev: Second,
|
||||
|
||||
/// Time spend in user space
|
||||
pub user: Second,
|
||||
|
||||
/// Time spent in system space
|
||||
pub system: Second,
|
||||
|
||||
/// Min time measured
|
||||
pub min: Second,
|
||||
|
||||
/// Max time measured
|
||||
pub max: Second,
|
||||
|
||||
/// All run time measurements
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub times: Option<Vec<Second>>,
|
||||
}
|
||||
|
||||
impl BenchmarkResult {
|
||||
/// Create a new entry with the given values.
|
||||
pub fn new(
|
||||
command: String,
|
||||
mean: Second,
|
||||
stddev: Second,
|
||||
user: Second,
|
||||
system: Second,
|
||||
min: Second,
|
||||
max: Second,
|
||||
times: Vec<Second>,
|
||||
) -> Self {
|
||||
BenchmarkResult {
|
||||
command,
|
||||
mean,
|
||||
stddev,
|
||||
user,
|
||||
system,
|
||||
min,
|
||||
max,
|
||||
times: Some(times),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user