Home > libalgo > Chrono

Chrono

概要

時間をはかる構造体.

実装

#[allow(dead_code)]
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
struct Chrono {
    st: std::time::SystemTime,
}

#[allow(dead_code)]
impl Chrono {
    pub fn new() -> Self {
        Self {
            st: std::time::SystemTime::now(),
        }
    }

    pub fn elapsed_ms(&self) -> i64 {
        let elapsed = self.st.elapsed().expect("failed getting elapsed time");
        elapsed.as_secs() as i64 * 1000 + elapsed.subsec_nanos() as i64 / 1_000_000
    }

    pub fn reset(&mut self) {
        *self = Self::new();
    }
}