wip: refactor: removing seams
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
same mf who else 2026-03-19 17:22:47 +02:00
parent 4e8d58d793
commit b0fbe3c173
18 changed files with 1724 additions and 1808 deletions

63
src/time.rs Normal file
View file

@ -0,0 +1,63 @@
use crate::*;
/// Performance counter
#[derive(Debug)]
pub struct PerfModel {
pub clock: quanta::Clock,
/// Measurement has a small cost. Disable it here.
pub enabled: bool,
// In nanoseconds. Time used by last iteration.
pub used: AtomicF64,
// In microseconds. Max prescribed time for iteration (frame, chunk...).
pub window: AtomicF64,
}
impl_default!(PerfModel: Self {
enabled: true,
clock: quanta::Clock::new(),
used: Default::default(),
window: Default::default(),
});
impl PerfModel {
pub fn get_t0 (&self) -> Option<u64> {
if self.enabled {
Some(self.clock.raw())
} else {
None
}
}
pub fn get_t1 (&self, t0: Option<u64>) -> Option<std::time::Duration> {
if let Some(t0) = t0 {
if self.enabled {
Some(self.clock.delta(t0, self.clock.raw()))
} else {
None
}
} else {
None
}
}
pub fn update (&self, t0: Option<u64>, microseconds: f64) {
if let Some(t0) = t0 {
let t1 = self.clock.raw();
self.used.store(self.clock.delta_as_nanos(t0, t1) as f64, Relaxed);
self.window.store(microseconds, Relaxed,);
}
}
pub fn percentage (&self) -> Option<f64> {
let window = self.window.load(Relaxed) * 1000.0;
if window > 0.0 {
let used = self.used.load(Relaxed);
Some(100.0 * used / window)
} else {
None
}
}
pub fn cycle <F: Fn(&Self)->T, T> (&self, call: &F) -> T {
let t0 = self.get_t0();
let result = call(self);
let _t1 = self.get_t1(t0).unwrap();
result
}
}