Add support for showing other metrics in the terminal

This commit is contained in:
David Peter committed 2026-10-06 12:53:42 +02:00
1 parent 7395dde05d
commit 908b33cc1d
31 files changed
+1514 -1898

No files matched your search

+108 -107
View File
@@ -2,19 +2,27 @@ use super::Exporter;
use crate::benchmark::benchmark_result::BenchmarkResult;
use crate::benchmark::measurement::{Measurement, Measurements};
use crate::export::asciidoc::AsciidocExporter;
use crate::export::markdown::MarkdownExporter;
use crate::export::orgmode::OrgmodeExporter;
use crate::quantity::{byte, second, Information, Time, TimeUnit, Zero};
use crate::{export::markdown::MarkdownExporter, options::SortOrder};
use crate::metric::{MetricSelection, Unit};
use crate::quantity::{byte, second, Information, Time, Zero};
use std::collections::BTreeMap;
use std::process::ExitStatus;
fn get_output<E: Exporter + Default>(
results: &[BenchmarkResult],
unit: Option<TimeUnit>,
sort_order: SortOrder,
) -> String {
fn get_output<E: Exporter + Default>(results: &[BenchmarkResult], unit: Option<Unit>) -> String {
let exporter = E::default();
String::from_utf8(exporter.serialize(results, unit, sort_order, None).unwrap()).unwrap()
String::from_utf8(
exporter
.serialize(
results,
MetricSelection {
unit,
..MetricSelection::default()
},
)
.unwrap(),
)
.unwrap()
}
/// Ensure the makrup output includes the table header and the multiple
@@ -92,41 +100,41 @@ fn test_markup_export_auto_ms() {
},
];
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, None, SortOrder::Command), @r#"
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, None), @r#"
| Command | Mean Time [ms] | Min [ms] | Max [ms] | Change |
|:---|---:|---:|---:|---:|
| `sleep 0.1` | 110.0 ± 26.5 | 90.0 | 140.0 | 1.00 |
| `sleep 2` | 3000.0 ± 1000.0 | 2000.0 | 4000.0 | 27.27 ± 11.21 |
| `sleep 0.1` | 110.0 ± 26.5 | 90.0 | 140.0 | reference |
| `sleep 2` | 3000.0 ± 1000.0 | 2000.0 | 4000.0 | +2627.3% |
"#);
insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, None, SortOrder::Command), @r#"
insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, None), @r#"
[cols="<,>,>,>,>"]
|===
| Command
| Mean [ms]
| Min [ms]
| Max [ms]
| Relative
| Command
| Mean Time [ms]
| Min [ms]
| Max [ms]
| Change
| `sleep 0.1`
| 110.0 ± 26.5
| 90.0
| 140.0
| 1.00
| `sleep 0.1`
| 110.0 ± 26.5
| 90.0
| 140.0
| reference
| `sleep 2`
| 3000.0 ± 1000.0
| 2000.0
| 4000.0
| 27.27 ± 11.21
| `sleep 2`
| 3000.0 ± 1000.0
| 2000.0
| 4000.0
| +2627.3%
|===
"#);
insta::assert_snapshot!(get_output::<OrgmodeExporter>(&results, None, SortOrder::Command), @r#"
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
insta::assert_snapshot!(get_output::<OrgmodeExporter>(&results, None), @r#"
| Command | Mean Time [ms] | Min [ms] | Max [ms] | Change |
|--+--+--+--+--|
| =sleep 0.1= | 110.0 ± 26.5 | 90.0 | 140.0 | 1.00 |
| =sleep 2= | 3000.0 ± 1000.0 | 2000.0 | 4000.0 | 27.27 ± 11.21 |
| =sleep 0.1= | 110.0 ± 26.5 | 90.0 | 140.0 | reference |
| =sleep 2= | 3000.0 ± 1000.0 | 2000.0 | 4000.0 | +2627.3% |
"#);
}
@@ -201,41 +209,41 @@ fn test_markup_export_auto_s() {
},
];
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, None, SortOrder::Command), @r#"
| Command | Mean [s] | Min [s] | Max [s] | Relative |
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, None), @r#"
| Command | Mean Time [s] | Min [s] | Max [s] | Change |
|:---|---:|---:|---:|---:|
| `sleep 2` | 2.200 ± 0.100 | 2.100 | 2.300 | 11.00 ± 5.52 |
| `sleep 0.1` | 0.200 ± 0.100 | 0.100 | 0.300 | 1.00 |
| `sleep 2` | 2.200 ± 0.100 | 2.100 | 2.300 | reference |
| `sleep 0.1` | 0.200 ± 0.100 | 0.100 | 0.300 | -90.9% |
"#);
insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, None, SortOrder::Command), @r#"
insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, None), @r#"
[cols="<,>,>,>,>"]
|===
| Command
| Mean [s]
| Min [s]
| Max [s]
| Relative
| Command
| Mean Time [s]
| Min [s]
| Max [s]
| Change
| `sleep 2`
| 2.200 ± 0.100
| 2.100
| 2.300
| 11.00 ± 5.52
| `sleep 2`
| 2.200 ± 0.100
| 2.100
| 2.300
| reference
| `sleep 0.1`
| 0.200 ± 0.100
| 0.100
| 0.300
| 1.00
| `sleep 0.1`
| 0.200 ± 0.100
| 0.100
| 0.300
| -90.9%
|===
"#);
insta::assert_snapshot!(get_output::<OrgmodeExporter>(&results, None, SortOrder::Command), @r#"
| Command | Mean [s] | Min [s] | Max [s] | Relative |
insta::assert_snapshot!(get_output::<OrgmodeExporter>(&results, None), @r#"
| Command | Mean Time [s] | Min [s] | Max [s] | Change |
|--+--+--+--+--|
| =sleep 2= | 2.200 ± 0.100 | 2.100 | 2.300 | 11.00 ± 5.52 |
| =sleep 0.1= | 0.200 ± 0.100 | 0.100 | 0.300 | 1.00 |
| =sleep 2= | 2.200 ± 0.100 | 2.100 | 2.300 | reference |
| =sleep 0.1= | 0.200 ± 0.100 | 0.100 | 0.300 | -90.9% |
"#);
}
@@ -310,41 +318,41 @@ fn test_markup_export_manual_ms() {
},
];
insta::assert_snapshot!(get_output::<MarkdownExporter>(&timing_results, Some(TimeUnit::MilliSecond), SortOrder::Command), @r#"
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
insta::assert_snapshot!(get_output::<MarkdownExporter>(&timing_results, Some(Unit { symbol: "ms", scale: 0.001 })), @r#"
| Command | Mean Time [ms] | Min [ms] | Max [ms] | Change |
|:---|---:|---:|---:|---:|
| `sleep 2` | 2200.0 ± 100.0 | 2100.0 | 2300.0 | 11.00 ± 5.52 |
| `sleep 0.1` | 200.0 ± 100.0 | 100.0 | 300.0 | 1.00 |
| `sleep 2` | 2200.0 ± 100.0 | 2100.0 | 2300.0 | reference |
| `sleep 0.1` | 200.0 ± 100.0 | 100.0 | 300.0 | -90.9% |
"#);
insta::assert_snapshot!(get_output::<AsciidocExporter>(&timing_results, Some(TimeUnit::MilliSecond), SortOrder::Command), @r#"
insta::assert_snapshot!(get_output::<AsciidocExporter>(&timing_results, Some(Unit { symbol: "ms", scale: 0.001 })), @r#"
[cols="<,>,>,>,>"]
|===
| Command
| Mean [ms]
| Min [ms]
| Max [ms]
| Relative
| Command
| Mean Time [ms]
| Min [ms]
| Max [ms]
| Change
| `sleep 2`
| 2200.0 ± 100.0
| 2100.0
| 2300.0
| 11.00 ± 5.52
| `sleep 2`
| 2200.0 ± 100.0
| 2100.0
| 2300.0
| reference
| `sleep 0.1`
| 200.0 ± 100.0
| 100.0
| 300.0
| 1.00
| `sleep 0.1`
| 200.0 ± 100.0
| 100.0
| 300.0
| -90.9%
|===
"#);
insta::assert_snapshot!(get_output::<OrgmodeExporter>(&timing_results, Some(TimeUnit::MilliSecond), SortOrder::Command), @r#"
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
insta::assert_snapshot!(get_output::<OrgmodeExporter>(&timing_results, Some(Unit { symbol: "ms", scale: 0.001 })), @r#"
| Command | Mean Time [ms] | Min [ms] | Max [ms] | Change |
|--+--+--+--+--|
| =sleep 2= | 2200.0 ± 100.0 | 2100.0 | 2300.0 | 11.00 ± 5.52 |
| =sleep 0.1= | 200.0 ± 100.0 | 100.0 | 300.0 | 1.00 |
| =sleep 2= | 2200.0 ± 100.0 | 2100.0 | 2300.0 | reference |
| =sleep 0.1= | 200.0 ± 100.0 | 100.0 | 300.0 | -90.9% |
"#);
}
@@ -418,40 +426,33 @@ fn test_markup_export_manual_s() {
},
];
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(TimeUnit::Second), SortOrder::Command), @r#"
| Command | Mean [s] | Min [s] | Max [s] | Relative |
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(Unit { symbol: "s", scale: 1.0 })), @r#"
| Command | Mean Time [s] | Min [s] | Max [s] | Change |
|:---|---:|---:|---:|---:|
| `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 |
| `sleep 2` | 2.020 ± 0.010 | 2.010 | 2.030 | reference |
| `sleep 0.1` | 0.120 ± 0.010 | 0.110 | 0.130 | -94.1% |
"#);
insta::assert_snapshot!(get_output::<MarkdownExporter>(&results, Some(TimeUnit::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 |
| `sleep 2` | 2.020 ± 0.010 | 2.010 | 2.030 | 16.83 ± 1.41 |
"#);
insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, Some(TimeUnit::Second), SortOrder::Command), @r#"
insta::assert_snapshot!(get_output::<AsciidocExporter>(&results, Some(Unit { symbol: "s", scale: 1.0 })), @r#"
[cols="<,>,>,>,>"]
|===
| Command
| Mean [s]
| Min [s]
| Max [s]
| Relative
| Command
| Mean Time [s]
| Min [s]
| Max [s]
| Change
| `sleep 2`
| 2.020 ± 0.010
| 2.010
| 2.030
| 16.83 ± 1.41
| `sleep 2`
| 2.020 ± 0.010
| 2.010
| 2.030
| reference
| `sleep 0.1`
| 0.120 ± 0.010
| 0.110
| 0.130
| 1.00
| `sleep 0.1`
| 0.120 ± 0.010
| 0.110
| 0.130
| -94.1%
|===
"#);
}