Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced performance metrics #790

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4c173fa
Introduce new BenchmarkRun struct
sharkdp Dec 29, 2024
02a94ec
Move user and system time
sharkdp Dec 29, 2024
3ec42a0
Use wait4 instead of getrusage
sharkdp Dec 29, 2024
ec0df72
Remove command_with_unused_parameters field
sharkdp Dec 29, 2024
fe836e3
Real => wall clock
sharkdp Dec 29, 2024
5bf07c7
Simplify run creation
sharkdp Dec 29, 2024
c92bccc
More simplifications
sharkdp Dec 29, 2024
65bee63
Runs => Measurements
sharkdp Dec 29, 2024
3347893
Units
sharkdp Dec 29, 2024
8936f8e
Switch to unit-safe quantities
sharkdp Dec 30, 2024
c41d660
Unify TimingResult/TimerResult/Measurement
sharkdp Jan 1, 2025
1303507
Rename to exit_code
sharkdp Jan 1, 2025
26fe4a5
Add unit information
sharkdp Jan 1, 2025
456dfd6
Add short unit
sharkdp Jan 4, 2025
2fc989b
Use uom
sharkdp Jan 4, 2025
6c5eae3
Use unit system in unix_timer
sharkdp Jan 4, 2025
d869e8a
Fix Windows timer
sharkdp Jan 4, 2025
3cdae0f
Move quantity module
sharkdp Jan 4, 2025
013754a
Refactoring
sharkdp Jan 5, 2025
9095846
Implement TimeUnit functions via uom
sharkdp Jan 5, 2025
acdbf71
Support minutes and hours
sharkdp Jan 5, 2025
d3d833a
Remove alternative constructors
sharkdp Jan 5, 2025
581c696
TODO comments
sharkdp Jan 5, 2025
3cc3247
Fix Windows includes
sharkdp Jan 5, 2025
f1e201e
Quantity API cleanup
sharkdp Jan 11, 2025
80d2862
Further simplification of the API
sharkdp Jan 11, 2025
fb8ba86
Do not use value_in for CSV export
sharkdp Jan 11, 2025
b7a904f
Represent memory usage as f64 as well
sharkdp Jan 11, 2025
44c8267
Get rid of value_in
sharkdp Jan 11, 2025
aabd8f4
Add test
sharkdp Jan 11, 2025
fede556
Yet another API iteration
sharkdp Jan 11, 2025
32b2295
Make memory units available
sharkdp Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ rand = "0.8"
shell-words = "1.0"
thiserror = "2.0"
anyhow = "1.0"
uom = { version = "0.36.0", default-features = false, features = [
"std",
"si",
"f64",
] }

[target.'cfg(not(windows))'.dependencies]
libc = "0.2"
Expand Down
82 changes: 41 additions & 41 deletions src/benchmark/benchmark_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,54 @@ use std::collections::BTreeMap;

use serde::Serialize;

use crate::util::units::Second;
use crate::benchmark::measurement::Measurements;
use crate::quantity::Time;

/// 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.
/// Parameter value and whether it was used in the command line template
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
pub struct Parameter {
pub value: String,
pub is_unused: bool,
}

/// Meta data and performance metrics for a single benchmark
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
pub struct BenchmarkResult {
/// The full command line of the program that is being benchmarked
pub command: String,

/// The full command line of the program that is being benchmarked, possibly including a list of
/// parameters that were not used in the command line template.
#[serde(skip_serializing)]
pub command_with_unused_parameters: String,

/// The average run time
pub mean: Second,

/// The standard deviation of all run times. Not available if only one run has been performed
pub stddev: Option<Second>,

/// The median run time
pub median: Second,

/// Time spent in user mode
pub user: Second,

/// Time spent in kernel mode
pub system: Second,

/// Minimum of all measured times
pub min: Second,

/// Maximum of all measured times
pub max: Second,

/// All run time measurements
#[serde(skip_serializing_if = "Option::is_none")]
pub times: Option<Vec<Second>>,

/// Maximum memory usage of the process, in bytes
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_usage_byte: Option<Vec<u64>>,

/// Exit codes of all command invocations
pub exit_codes: Vec<Option<i32>>,
/// Performance metric measurements and exit codes for each run
#[serde(flatten)]
pub measurements: Measurements,

/// Parameter values for this benchmark
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub parameters: BTreeMap<String, String>,
pub parameters: BTreeMap<String, Parameter>,
}

impl BenchmarkResult {
/// The average wall clock time
pub fn mean_wall_clock_time(&self) -> Time {
self.measurements.time_wall_clock_mean()
}

/// The full command line of the program that is being benchmarked, possibly including a list of
/// parameters that were not used in the command line template.
pub fn command_with_unused_parameters(&self) -> String {
let parameters = self
.parameters
.iter()
.filter(|(_, parameter)| parameter.is_unused)
.fold(String::new(), |output, (name, parameter)| {
output + &format!("{name} = {value}, ", value = parameter.value)
});
let parameters = parameters.trim_end_matches(", ");
let parameters = if parameters.is_empty() {
"".into()
} else {
format!(" ({parameters})")
};

format!("{}{}", self.command, parameters)
}
}
Loading
Loading