Simplifications

This commit is contained in:
David Peter committed 2026-10-06 13:34:03 +02:00
1 parent 715994847f
commit 4f893b505e
10 files changed
+100 -84

No files matched your search

+3
View File
@@ -220,6 +220,7 @@ impl Executor for ShellExecutor<'_> {
ensure_non_negative(measurement.time_user - spawning_time.time_user);
measurement.time_system =
ensure_non_negative(measurement.time_system - spawning_time.time_system);
measurement.time_cpu = measurement.time_user + measurement.time_system;
}
Ok(measurement)
@@ -278,6 +279,7 @@ impl Executor for ShellExecutor<'_> {
self.shell_spawning_time = Some(Measurement {
time_wall_clock: measurements.time_wall_clock_mean(),
time_cpu: measurements.time_user_mean() + measurements.time_system_mean(),
time_user: measurements.time_user_mean(),
time_system: measurements.time_system_mean(),
memory_peak_resident: None,
@@ -337,6 +339,7 @@ impl Executor for MockExecutor {
Ok(Measurement {
time_wall_clock: Self::extract_time(command.get_command_line()),
time_cpu: Time::zero(),
time_user: Time::zero(),
time_system: Time::zero(),
memory_peak_resident: Some(Information::zero()),
+4 -26
View File
@@ -78,6 +78,10 @@ pub struct Measurement {
#[serde(serialize_with = "serialize_time")]
pub time_wall_clock: Time,
/// Total CPU time (user and kernel mode)
#[serde(serialize_with = "serialize_time")]
pub time_cpu: Time,
/// Time spent in user mode
#[serde(serialize_with = "serialize_time")]
pub time_user: Time,
@@ -101,34 +105,8 @@ pub struct Measurement {
pub exit_status: ExitStatus,
}
impl Measurement {
/// Total CPU time for this run, including user and kernel mode.
pub fn time_cpu(&self) -> Time {
self.time_user + self.time_system
}
}
fn serialize_measurements<S>(measurements: &[Measurement], serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
#[derive(Serialize)]
struct WithCpuTime<'a> {
#[serde(flatten)]
measurement: &'a Measurement,
#[serde(serialize_with = "serialize_time")]
time_cpu: Time,
}
serializer.collect_seq(measurements.iter().map(|measurement| WithCpuTime {
measurement,
time_cpu: measurement.time_cpu(),
}))
}
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
pub struct Measurements {
#[serde(serialize_with = "serialize_measurements")]
pub measurements: Vec<Measurement>,
}
+12 -12
View File
@@ -87,6 +87,9 @@ fn scheduler_basic() -> Result<()> {
- time_wall_clock:
value: 0.123
unit: second
time_cpu:
value: 0
unit: second
time_user:
value: 0
unit: second
@@ -97,12 +100,12 @@ fn scheduler_basic() -> Result<()> {
value: 0
unit: byte
exit_code: 0
time_cpu:
value: 0
unit: second
- time_wall_clock:
value: 0.123
unit: second
time_cpu:
value: 0
unit: second
time_user:
value: 0
unit: second
@@ -113,14 +116,14 @@ fn scheduler_basic() -> Result<()> {
value: 0
unit: byte
exit_code: 0
time_cpu:
value: 0
unit: second
- command: sleep 0.456
measurements:
- time_wall_clock:
value: 0.456
unit: second
time_cpu:
value: 0
unit: second
time_user:
value: 0
unit: second
@@ -131,12 +134,12 @@ fn scheduler_basic() -> Result<()> {
value: 0
unit: byte
exit_code: 0
time_cpu:
value: 0
unit: second
- time_wall_clock:
value: 0.456
unit: second
time_cpu:
value: 0
unit: second
time_user:
value: 0
unit: second
@@ -147,9 +150,6 @@ fn scheduler_basic() -> Result<()> {
value: 0
unit: byte
exit_code: 0
time_cpu:
value: 0
unit: second
");
Ok(())
+6
View File
@@ -94,6 +94,7 @@ fn test_csv() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(7.0),
time_cpu: Time::new::<second>(7.0),
time_user: Time::new::<second>(7.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -102,6 +103,7 @@ fn test_csv() {
},
Measurement {
time_wall_clock: Time::new::<second>(8.0),
time_cpu: Time::new::<second>(8.0),
time_user: Time::new::<second>(8.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -110,6 +112,7 @@ fn test_csv() {
},
Measurement {
time_wall_clock: Time::new::<second>(12.0),
time_cpu: Time::new::<second>(12.0),
time_user: Time::new::<second>(12.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -141,6 +144,7 @@ fn test_csv() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(17.0),
time_cpu: Time::new::<second>(17.0),
time_user: Time::new::<second>(17.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -149,6 +153,7 @@ fn test_csv() {
},
Measurement {
time_wall_clock: Time::new::<second>(18.0),
time_cpu: Time::new::<second>(18.0),
time_user: Time::new::<second>(18.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -157,6 +162,7 @@ fn test_csv() {
},
Measurement {
time_wall_clock: Time::new::<second>(19.0),
time_cpu: Time::new::<second>(19.0),
time_user: Time::new::<second>(19.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
+24
View File
@@ -41,6 +41,7 @@ fn test_markup_export_auto_ms() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(0.09),
time_cpu: Time::new::<second>(0.09),
time_user: Time::new::<second>(0.09),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -49,6 +50,7 @@ fn test_markup_export_auto_ms() {
},
Measurement {
time_wall_clock: Time::new::<second>(0.10),
time_cpu: Time::new::<second>(0.10),
time_user: Time::new::<second>(0.10),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -57,6 +59,7 @@ fn test_markup_export_auto_ms() {
},
Measurement {
time_wall_clock: Time::new::<second>(0.14),
time_cpu: Time::new::<second>(0.14),
time_user: Time::new::<second>(0.14),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -73,6 +76,7 @@ fn test_markup_export_auto_ms() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(2.0),
time_cpu: Time::new::<second>(2.0),
time_user: Time::new::<second>(2.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -81,6 +85,7 @@ fn test_markup_export_auto_ms() {
},
Measurement {
time_wall_clock: Time::new::<second>(3.0),
time_cpu: Time::new::<second>(3.0),
time_user: Time::new::<second>(3.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -89,6 +94,7 @@ fn test_markup_export_auto_ms() {
},
Measurement {
time_wall_clock: Time::new::<second>(4.0),
time_cpu: Time::new::<second>(4.0),
time_user: Time::new::<second>(4.0),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -150,6 +156,7 @@ fn test_markup_export_auto_s() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(2.1),
time_cpu: Time::new::<second>(2.1),
time_user: Time::new::<second>(2.1),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -158,6 +165,7 @@ fn test_markup_export_auto_s() {
},
Measurement {
time_wall_clock: Time::new::<second>(2.2),
time_cpu: Time::new::<second>(2.2),
time_user: Time::new::<second>(2.2),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -166,6 +174,7 @@ fn test_markup_export_auto_s() {
},
Measurement {
time_wall_clock: Time::new::<second>(2.3),
time_cpu: Time::new::<second>(2.3),
time_user: Time::new::<second>(2.3),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -182,6 +191,7 @@ fn test_markup_export_auto_s() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(0.1),
time_cpu: Time::new::<second>(0.1),
time_user: Time::new::<second>(0.1),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -190,6 +200,7 @@ fn test_markup_export_auto_s() {
},
Measurement {
time_wall_clock: Time::new::<second>(0.2),
time_cpu: Time::new::<second>(0.2),
time_user: Time::new::<second>(0.2),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -198,6 +209,7 @@ fn test_markup_export_auto_s() {
},
Measurement {
time_wall_clock: Time::new::<second>(0.3),
time_cpu: Time::new::<second>(0.3),
time_user: Time::new::<second>(0.3),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -259,6 +271,7 @@ fn test_markup_export_manual_ms() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(2.1),
time_cpu: Time::new::<second>(2.1),
time_user: Time::new::<second>(2.1),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -267,6 +280,7 @@ fn test_markup_export_manual_ms() {
},
Measurement {
time_wall_clock: Time::new::<second>(2.2),
time_cpu: Time::new::<second>(2.2),
time_user: Time::new::<second>(2.2),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -275,6 +289,7 @@ fn test_markup_export_manual_ms() {
},
Measurement {
time_wall_clock: Time::new::<second>(2.3),
time_cpu: Time::new::<second>(2.3),
time_user: Time::new::<second>(2.3),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -291,6 +306,7 @@ fn test_markup_export_manual_ms() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(0.1),
time_cpu: Time::new::<second>(0.1),
time_user: Time::new::<second>(0.1),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -299,6 +315,7 @@ fn test_markup_export_manual_ms() {
},
Measurement {
time_wall_clock: Time::new::<second>(0.2),
time_cpu: Time::new::<second>(0.2),
time_user: Time::new::<second>(0.2),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -307,6 +324,7 @@ fn test_markup_export_manual_ms() {
},
Measurement {
time_wall_clock: Time::new::<second>(0.3),
time_cpu: Time::new::<second>(0.3),
time_user: Time::new::<second>(0.3),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -367,6 +385,7 @@ fn test_markup_export_manual_s() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(2.01),
time_cpu: Time::new::<second>(2.01),
time_user: Time::new::<second>(2.01),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -375,6 +394,7 @@ fn test_markup_export_manual_s() {
},
Measurement {
time_wall_clock: Time::new::<second>(2.02),
time_cpu: Time::new::<second>(2.02),
time_user: Time::new::<second>(2.02),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -383,6 +403,7 @@ fn test_markup_export_manual_s() {
},
Measurement {
time_wall_clock: Time::new::<second>(2.03),
time_cpu: Time::new::<second>(2.03),
time_user: Time::new::<second>(2.03),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -399,6 +420,7 @@ fn test_markup_export_manual_s() {
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(0.11),
time_cpu: Time::new::<second>(0.11),
time_user: Time::new::<second>(0.11),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -407,6 +429,7 @@ fn test_markup_export_manual_s() {
},
Measurement {
time_wall_clock: Time::new::<second>(0.12),
time_cpu: Time::new::<second>(0.12),
time_user: Time::new::<second>(0.12),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
@@ -415,6 +438,7 @@ fn test_markup_export_manual_s() {
},
Measurement {
time_wall_clock: Time::new::<second>(0.13),
time_cpu: Time::new::<second>(0.13),
time_user: Time::new::<second>(0.13),
time_system: Time::zero(),
memory_peak_resident: Some(Information::new::<byte>(1024.)),
+2 -1
View File
@@ -69,7 +69,7 @@ impl Metric {
let counters = &measurement.hardware_counters;
match self {
Self::TimeWallClock => Some(measurement.time_wall_clock.get::<second>()),
Self::TimeCpu => Some(measurement.time_cpu().get::<second>()),
Self::TimeCpu => Some(measurement.time_cpu.get::<second>()),
Self::TimeUser => Some(measurement.time_user.get::<second>()),
Self::TimeSystem => Some(measurement.time_system.get::<second>()),
Self::MemoryPeakResident => measurement.memory_peak_resident.map(|v| v.get::<byte>()),
@@ -362,6 +362,7 @@ mod tests {
[(1.0, 3.0), (3.0, 1.0)]
.iter()
.map(|&(user, system)| Measurement {
time_cpu: Time::new::<second>(user + system),
time_user: Time::new::<second>(user),
time_system: Time::new::<second>(system),
..Measurement::default()
+1
View File
@@ -118,6 +118,7 @@ pub fn execute_and_measure(
Ok(Measurement {
time_wall_clock,
time_cpu: time_user + time_system,
time_user,
time_system,
memory_peak_resident,
@@ -1,5 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 1278
info:
program: hyperfine
args:
@@ -38,6 +39,10 @@ exit_code: 0
"value": 1.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -50,17 +55,17 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
},
{
"time_wall_clock": {
"value": 1.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -73,11 +78,7 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
}
],
"summary": {
@@ -136,6 +137,10 @@ exit_code: 0
"value": 2.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -148,17 +153,17 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
},
{
"time_wall_clock": {
"value": 2.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -171,11 +176,7 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
}
],
"summary": {
@@ -1,5 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 1305
info:
program: hyperfine
args:
@@ -38,6 +39,10 @@ exit_code: 0
"value": 1.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -50,17 +55,17 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
},
{
"time_wall_clock": {
"value": 1.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -73,11 +78,7 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
}
],
"parameters": {
@@ -142,6 +143,10 @@ exit_code: 0
"value": 2.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -154,17 +159,17 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
},
{
"time_wall_clock": {
"value": 2.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -177,11 +182,7 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
}
],
"parameters": {
@@ -1,5 +1,6 @@
---
source: tests/integration_tests.rs
assertion_line: 1294
info:
program: hyperfine
args:
@@ -33,6 +34,10 @@ exit_code: 0
"value": 1.0,
"unit": "second"
},
"time_cpu": {
"value": 0.0,
"unit": "second"
},
"time_user": {
"value": 0.0,
"unit": "second"
@@ -45,11 +50,7 @@ exit_code: 0
"value": 0.0,
"unit": "byte"
},
"exit_code": 0,
"time_cpu": {
"value": 0.0,
"unit": "second"
}
"exit_code": 0
}
],
"summary": {