Skip to content

Commit

Permalink
Serialize command parameters to data output files
Browse files Browse the repository at this point in the history
This patch adds any parameter used to data output files (currently JSON
and CSV files). With that users have direct access to both input values
(i.e., benchmark parameters) and the resulting timings which should
simplify follow-up analyses.
  • Loading branch information
bbannier authored and sharkdp committed Jan 18, 2019
1 parent 9afe57d commit b252531
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/hyperfine/benchmark.rs
Expand Up @@ -412,5 +412,6 @@ pub fn run_benchmark(
t_min,
t_max,
times_real,
cmd.get_parameter().map(|p| p.1),
))
}
8 changes: 8 additions & 0 deletions src/hyperfine/export/markdown.rs
Expand Up @@ -83,6 +83,7 @@ fn test_markdown_format_ms() {
0.1023, // min
0.1080, // max
vec![0.1, 0.1, 0.1], // times
None, // parameter
));

timing_results.push(BenchmarkResult::new(
Expand All @@ -94,6 +95,7 @@ fn test_markdown_format_ms() {
2.0020, // min
2.0080, // max
vec![2.0, 2.0, 2.0], // times
None, // parameter
));

let formatted = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
Expand Down Expand Up @@ -126,6 +128,7 @@ fn test_markdown_format_s() {
2.0020, // min
2.0080, // max
vec![2.0, 2.0, 2.0], // times
None, // parameter
));

timing_results.push(BenchmarkResult::new(
Expand All @@ -137,6 +140,7 @@ fn test_markdown_format_s() {
0.1023, // min
0.1080, // max
vec![0.1, 0.1, 0.1], // times
None, // parameter
));

let formatted = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
Expand Down Expand Up @@ -168,6 +172,7 @@ fn test_markdown_format_time_unit_s() {
0.1023, // min
0.1080, // max
vec![0.1, 0.1, 0.1], // times
None, // parameter
));

timing_results.push(BenchmarkResult::new(
Expand All @@ -179,6 +184,7 @@ fn test_markdown_format_time_unit_s() {
2.0020, // min
2.0080, // max
vec![2.0, 2.0, 2.0], // times
None, // parameter
));

let formatted = String::from_utf8(
Expand Down Expand Up @@ -216,6 +222,7 @@ fn test_markdown_format_time_unit_ms() {
2.0020, // min
2.0080, // max
vec![2.0, 2.0, 2.0], // times
None, // parameter
));

timing_results.push(BenchmarkResult::new(
Expand All @@ -227,6 +234,7 @@ fn test_markdown_format_time_unit_ms() {
0.1023, // min
0.1080, // max
vec![0.1, 0.1, 0.1], // times
None, // parameter
));

let formatted = String::from_utf8(
Expand Down
6 changes: 6 additions & 0 deletions src/hyperfine/types.rs
Expand Up @@ -173,6 +173,10 @@ pub struct BenchmarkResult {
/// All run time measurements
#[serde(skip_serializing_if = "Option::is_none")]
pub times: Option<Vec<Second>>,

/// Any parameter used
#[serde(skip_serializing_if = "Option::is_none")]
pub parameter: Option<i32>,
}

impl BenchmarkResult {
Expand All @@ -186,6 +190,7 @@ impl BenchmarkResult {
min: Second,
max: Second,
times: Vec<Second>,
parameter: Option<i32>,
) -> Self {
BenchmarkResult {
command,
Expand All @@ -196,6 +201,7 @@ impl BenchmarkResult {
min,
max,
times: Some(times),
parameter,
}
}
}

0 comments on commit b252531

Please sign in to comment.