Add short unit

This commit is contained in:
David Peter authored and David Peter committed 2026-10-05 15:58:57 +02:00
1 parent a119cbaf2d
commit 9ec7a9c920
2 files changed
+86 -17

No files matched your search

+22 -1
View File
@@ -85,6 +85,26 @@ impl<
self.0
}
const fn unit_name(&self) -> &'static str {
match (IS_TIME, IS_INFORMATION) {
(true, false) => match METRIC_PREFIX_TIME {
-6 => "µs",
-3 => "ms",
0 => "s",
_ => unreachable!(),
},
(false, true) => match BINARY_PREFIX_INFORMATION {
0 => "B",
10 => "KiB",
20 => "MiB",
30 => "GiB",
40 => "TiB",
_ => unreachable!(),
},
_ => unreachable!(),
}
}
const fn unit_name_long(&self) -> &'static str {
match (IS_TIME, IS_INFORMATION) {
(true, false) => match METRIC_PREFIX_TIME {
@@ -179,7 +199,8 @@ impl<
{
let mut state = serializer.serialize_struct("Quantity", 2)?;
state.serialize_field("value", &self.0)?;
state.serialize_field("unit", self.unit_name_long())?;
state.serialize_field("unit", self.unit_name())?;
state.serialize_field("unit_long", self.unit_name_long())?;
state.end()
}
}
+64 -16
View File
@@ -206,27 +206,75 @@ fn scheduler_basic() -> Result<()> {
insta::assert_yaml_snapshot!(generate_results(&["--runs=2", "sleep 0.123", "sleep 0.456"])?, @r#"
- command: sleep 0.123
measurements:
- time_wall_clock: 0.123
time_user: 0
time_system: 0
peak_memory_usage: 0
- time_wall_clock:
value: 0.123
unit: s
unit_long: second
time_user:
value: 0
unit: s
unit_long: second
time_system:
value: 0
unit: s
unit_long: second
peak_memory_usage:
value: 0
unit: B
unit_long: byte
exit_code: 0
- time_wall_clock: 0.123
time_user: 0
time_system: 0
peak_memory_usage: 0
- time_wall_clock:
value: 0.123
unit: s
unit_long: second
time_user:
value: 0
unit: s
unit_long: second
time_system:
value: 0
unit: s
unit_long: second
peak_memory_usage:
value: 0
unit: B
unit_long: byte
exit_code: 0
- command: sleep 0.456
measurements:
- time_wall_clock: 0.456
time_user: 0
time_system: 0
peak_memory_usage: 0
- time_wall_clock:
value: 0.456
unit: s
unit_long: second
time_user:
value: 0
unit: s
unit_long: second
time_system:
value: 0
unit: s
unit_long: second
peak_memory_usage:
value: 0
unit: B
unit_long: byte
exit_code: 0
- time_wall_clock: 0.456
time_user: 0
time_system: 0
peak_memory_usage: 0
- time_wall_clock:
value: 0.456
unit: s
unit_long: second
time_user:
value: 0
unit: s
unit_long: second
time_system:
value: 0
unit: s
unit_long: second
peak_memory_usage:
value: 0
unit: B
unit_long: byte
exit_code: 0
"#);