From 9ec7a9c920f6f242612b3f20e4239488651b09af Mon Sep 17 00:00:00 2001 From: David Peter Date: Mon, 5 Oct 2026 14:16:56 +0200 Subject: [PATCH] Add short unit --- src/benchmark/quantity.rs | 23 ++++++++++- src/benchmark/scheduler.rs | 80 ++++++++++++++++++++++++++++++-------- 2 files changed, 86 insertions(+), 17 deletions(-) diff --git a/src/benchmark/quantity.rs b/src/benchmark/quantity.rs index bc64c3f..8e73fbf 100644 --- a/src/benchmark/quantity.rs +++ b/src/benchmark/quantity.rs @@ -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() } } diff --git a/src/benchmark/scheduler.rs b/src/benchmark/scheduler.rs index edc8ccd..90b5352 100644 --- a/src/benchmark/scheduler.rs +++ b/src/benchmark/scheduler.rs @@ -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 "#);