mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Introduce new BenchmarkRun struct
This commit is contained in:
1 parent
46e1f9f2c1
commit
14d773998a
7 files changed
+247
-264
No files matched your search
+36
-49
@@ -44,13 +44,13 @@ impl Exporter for CsvExporter {
|
||||
for res in results {
|
||||
let mut fields = vec![Cow::Borrowed(res.command.as_bytes())];
|
||||
for f in &[
|
||||
res.mean_wall_clock_time(),
|
||||
res.measurements.stddev().unwrap_or_default(),
|
||||
res.measurements.median(),
|
||||
res.measurements.time_user_mean(),
|
||||
res.measurements.time_system_mean(),
|
||||
res.measurements.min(),
|
||||
res.measurements.max(),
|
||||
res.mean(),
|
||||
res.stddev().unwrap_or(0.0),
|
||||
res.median(),
|
||||
res.user,
|
||||
res.system,
|
||||
res.min(),
|
||||
res.max(),
|
||||
] {
|
||||
fields.push(Cow::Owned(
|
||||
f.format_with_precision(CSV_UNIT, CSV_PRECISION)
|
||||
@@ -67,6 +67,9 @@ impl Exporter for CsvExporter {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::benchmark::benchmark_result::BenchmarkRun;
|
||||
|
||||
#[test]
|
||||
fn test_csv() {
|
||||
use crate::benchmark::benchmark_result::Parameter;
|
||||
@@ -82,29 +85,21 @@ fn test_csv() {
|
||||
BenchmarkResult {
|
||||
command: String::from("command_a"),
|
||||
command_with_unused_parameters: String::from("command_a"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(7.0),
|
||||
time_user: Time::new::<second>(7.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 3.0,
|
||||
system: 4.0,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 7.0,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(8.0),
|
||||
time_user: Time::new::<second>(8.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 8.0,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(12.0),
|
||||
time_user: Time::new::<second>(12.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 12.0,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: {
|
||||
let mut params = BTreeMap::new();
|
||||
params.insert(
|
||||
@@ -127,29 +122,21 @@ fn test_csv() {
|
||||
BenchmarkResult {
|
||||
command: String::from("command_b"),
|
||||
command_with_unused_parameters: String::from("command_b"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(17.0),
|
||||
time_user: Time::new::<second>(17.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 13.0,
|
||||
system: 14.0,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 17.0,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(18.0),
|
||||
time_user: Time::new::<second>(18.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 18.0,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(19.0),
|
||||
time_user: Time::new::<second>(19.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 19.0,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: {
|
||||
let mut params = BTreeMap::new();
|
||||
params.insert(
|
||||
@@ -180,7 +167,7 @@ fn test_csv() {
|
||||
|
||||
insta::assert_snapshot!(actual, @r#"
|
||||
command,mean,stddev,median,user,system,min,max,parameter_bar,parameter_foo
|
||||
command_a,9.000000,2.645751,8.000000,9.000000,0.000000,7.000000,12.000000,two,one
|
||||
command_b,18.000000,1.000000,18.000000,18.000000,0.000000,17.000000,19.000000,seven,one
|
||||
command_a,9,2.6457513110645907,8,3,4,7,12,two,one
|
||||
command_b,18,1,18,13,14,17,19,seven,one
|
||||
"#);
|
||||
}
|
||||
@@ -53,9 +53,9 @@ pub trait MarkupExporter {
|
||||
let cmd_str = measurement
|
||||
.command_with_unused_parameters
|
||||
.replace('|', "\\|");
|
||||
let mean_str = measurement.mean_wall_clock_time().format_value(unit);
|
||||
let stddev_str = if let Some(stddev) = measurement.measurements.stddev() {
|
||||
format!(" ± {}", stddev.format_value(unit))
|
||||
let mean_str = format_duration_value(measurement.mean(), Some(unit)).0;
|
||||
let stddev_str = if let Some(stddev) = measurement.stddev() {
|
||||
format!(" ± {}", format_duration_value(stddev, Some(unit)).0)
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
@@ -116,7 +116,7 @@ pub trait MarkupExporter {
|
||||
fn determine_unit_from_results(results: &[BenchmarkResult]) -> TimeUnit {
|
||||
if let Some(first_result) = results.first() {
|
||||
// Use the first BenchmarkResult entry to determine the unit for all entries.
|
||||
first_result.mean_wall_clock_time().suitable_unit()
|
||||
format_duration_value(first_result.mean(), None).1
|
||||
} else {
|
||||
// Default to `Second`.
|
||||
TimeUnit::Second
|
||||
|
||||
+99
-164
@@ -1,6 +1,5 @@
|
||||
use super::Exporter;
|
||||
use crate::benchmark::benchmark_result::BenchmarkResult;
|
||||
use crate::benchmark::measurement::{Measurement, Measurements};
|
||||
use crate::benchmark::benchmark_result::{BenchmarkResult, BenchmarkRun};
|
||||
use crate::export::asciidoc::AsciidocExporter;
|
||||
use crate::export::orgmode::OrgmodeExporter;
|
||||
use crate::quantity::{byte, second, Information, Time, TimeUnit, Zero};
|
||||
@@ -29,57 +28,41 @@ fn test_markup_export_auto_ms() {
|
||||
BenchmarkResult {
|
||||
command: String::from("sleep 0.1"),
|
||||
command_with_unused_parameters: String::from("sleep 0.1"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.09),
|
||||
time_user: Time::new::<second>(0.09),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 0.0009,
|
||||
system: 0.0011,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.09,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.10),
|
||||
time_user: Time::new::<second>(0.10),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.10,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.14),
|
||||
time_user: Time::new::<second>(0.14),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.14,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: BTreeMap::new(),
|
||||
},
|
||||
BenchmarkResult {
|
||||
command: String::from("sleep 2"),
|
||||
command_with_unused_parameters: String::from("sleep 2"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.0),
|
||||
time_user: Time::new::<second>(2.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 0.0009,
|
||||
system: 0.0012,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.0,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(3.0),
|
||||
time_user: Time::new::<second>(3.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 3.0,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(4.0),
|
||||
time_user: Time::new::<second>(4.0),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 4.0,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: BTreeMap::new(),
|
||||
},
|
||||
];
|
||||
@@ -130,57 +113,41 @@ fn test_markup_export_auto_s() {
|
||||
BenchmarkResult {
|
||||
command: String::from("sleep 2"),
|
||||
command_with_unused_parameters: String::from("sleep 2"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.1),
|
||||
time_user: Time::new::<second>(2.1),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 0.0009,
|
||||
system: 0.0012,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.1,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.2),
|
||||
time_user: Time::new::<second>(2.2),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.2,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.3),
|
||||
time_user: Time::new::<second>(2.3),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.3,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: BTreeMap::new(),
|
||||
},
|
||||
BenchmarkResult {
|
||||
command: String::from("sleep 0.1"),
|
||||
command_with_unused_parameters: String::from("sleep 0.1"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.1),
|
||||
time_user: Time::new::<second>(0.1),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 0.0009,
|
||||
system: 0.0011,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.1,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.2),
|
||||
time_user: Time::new::<second>(0.2),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.2,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.3),
|
||||
time_user: Time::new::<second>(0.3),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.3,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: BTreeMap::new(),
|
||||
},
|
||||
];
|
||||
@@ -231,57 +198,41 @@ fn test_markup_export_manual_ms() {
|
||||
BenchmarkResult {
|
||||
command: String::from("sleep 2"),
|
||||
command_with_unused_parameters: String::from("sleep 2"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.1),
|
||||
time_user: Time::new::<second>(2.1),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 0.0009,
|
||||
system: 0.0012,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.1,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.2),
|
||||
time_user: Time::new::<second>(2.2),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.2,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.3),
|
||||
time_user: Time::new::<second>(2.3),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.3,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: BTreeMap::new(),
|
||||
},
|
||||
BenchmarkResult {
|
||||
command: String::from("sleep 0.1"),
|
||||
command_with_unused_parameters: String::from("sleep 0.1"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.1),
|
||||
time_user: Time::new::<second>(0.1),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 0.0009,
|
||||
system: 0.0011,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.1,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.2),
|
||||
time_user: Time::new::<second>(0.2),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.2,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.3),
|
||||
time_user: Time::new::<second>(0.3),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.3,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: BTreeMap::new(),
|
||||
},
|
||||
];
|
||||
@@ -331,69 +282,53 @@ fn test_markup_export_manual_s() {
|
||||
BenchmarkResult {
|
||||
command: String::from("sleep 2"),
|
||||
command_with_unused_parameters: String::from("sleep 2"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.01),
|
||||
time_user: Time::new::<second>(2.01),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 0.0009,
|
||||
system: 0.0012,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.01,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.02),
|
||||
time_user: Time::new::<second>(2.02),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.02,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(2.03),
|
||||
time_user: Time::new::<second>(2.03),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 2.03,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: BTreeMap::new(),
|
||||
},
|
||||
BenchmarkResult {
|
||||
command: String::from("sleep 0.1"),
|
||||
command_with_unused_parameters: String::from("sleep 0.1"),
|
||||
measurements: Measurements::new(vec![
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.11),
|
||||
time_user: Time::new::<second>(0.11),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
user: 0.0009,
|
||||
system: 0.0011,
|
||||
runs: vec![
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.11,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.12),
|
||||
time_user: Time::new::<second>(0.12),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.12,
|
||||
},
|
||||
Measurement {
|
||||
time_wall_clock: Time::new::<second>(0.13),
|
||||
time_user: Time::new::<second>(0.13),
|
||||
time_system: Time::zero(),
|
||||
peak_memory_usage: Information::new::<byte>(1024.),
|
||||
exit_status: ExitStatus::default(),
|
||||
BenchmarkRun {
|
||||
wall_clock_time: 0.13,
|
||||
},
|
||||
]),
|
||||
],
|
||||
memory_usage_byte: None,
|
||||
exit_codes: vec![Some(0), Some(0), Some(0)],
|
||||
parameters: BTreeMap::new(),
|
||||
},
|
||||
];
|
||||
|
||||
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(TimeUnit::Second), SortOrder::Command), @r#"
|
||||
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(Unit::Second), SortOrder::Command), @r#"
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `sleep 2` | 2.020 ± 0.010 | 2.010 | 2.030 | 16.83 ± 1.41 |
|
||||
| `sleep 0.1` | 0.120 ± 0.010 | 0.110 | 0.130 | 1.00 |
|
||||
"#);
|
||||
|
||||
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(TimeUnit::Second), SortOrder::MeanTime), @r#"
|
||||
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(Unit::Second), SortOrder::MeanTime), @r#"
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `sleep 0.1` | 0.120 ± 0.010 | 0.110 | 0.130 | 1.00 |
|
||||
|
||||
Reference in new issue
Block a user