Switch to unit-safe quantities

This commit is contained in:
David Peter authored and David Peter committed 2026-10-05 15:58:56 +02:00
1 parent 914d5cbc59
commit f9aa299c0f
15 files changed
+399 -287

No files matched your search

+2 -2
View File
@@ -16,7 +16,7 @@ use std::os::fd::AsFd;
#[cfg(target_os = "windows")]
use windows_sys::Win32::System::Threading::CREATE_SUSPENDED;
use crate::benchmark::measurement::Measurement;
use crate::benchmark::quantity::{Byte, Second};
use wall_clock_timer::WallClockTimer;
use std::io::Read;
@@ -30,7 +30,7 @@ pub struct TimerResult {
pub time_wall_clock: Second,
pub time_user: Second,
pub time_system: Second,
pub memory_usage_byte: u64,
pub memory_usage_byte: Byte,
/// The exit status of the process
pub status: ExitStatus,
}
+8 -8
View File
@@ -8,22 +8,22 @@ use std::process::{Child, ExitStatus};
use anyhow::Result;
use crate::util::units::Second;
use crate::benchmark::quantity::{Byte, Second};
#[derive(Debug, Copy, Clone)]
struct ResourceUsage {
/// Total amount of time spent executing in user mode
pub user_usec: Second,
pub user_usec: f64,
/// Total amount of time spent executing in kernel mode
pub system_usec: Second,
pub system_usec: f64,
/// Maximum amount of memory used by the process, in bytes
pub memory_usage_byte: i64,
}
#[allow(clippy::useless_conversion)]
fn timeval_to_seconds(tv: libc::timeval) -> Second {
fn timeval_to_seconds(tv: libc::timeval) -> f64 {
const MICROSEC_PER_SEC: i64 = 1000 * 1000;
(i64::from(tv.tv_sec) * MICROSEC_PER_SEC + i64::from(tv.tv_usec)) as f64 * 1e-6
}
@@ -68,13 +68,13 @@ impl CPUTimer {
Self {}
}
pub fn stop(&self, child: Child) -> Result<(ExitStatus, Second, Second, u64)> {
pub fn stop(&self, child: Child) -> Result<(ExitStatus, Second, Second, Byte)> {
let (status, usage) = wait4(child)?;
Ok((
status,
usage.user_usec,
usage.system_usec,
u64::try_from(usage.memory_usage_byte).unwrap_or(0),
Second::new(usage.user_usec),
Second::new(usage.system_usec),
Byte::new(u64::try_from(usage.memory_usage_byte).unwrap_or(0)),
))
}
}
+3 -4
View File
@@ -1,6 +1,6 @@
use std::time::Instant;
use crate::quantity::{nanosecond, second, Time};
use crate::benchmark::quantity::Second;
pub struct WallClockTimer {
start: Instant,
@@ -15,8 +15,7 @@ impl WallClockTimer {
pub fn stop(&self) -> Time {
let duration = self.start.elapsed();
Time::new::<second>(duration.as_secs() as f64)
+ Time::new::<nanosecond>(duration.subsec_nanos() as f64)
// TODO
Second::new(duration.as_secs() as f64 + f64::from(duration.subsec_nanos()) * 1e-9)
}
}