X-Git-Url: https://i11git.iti.kit.edu/anon-gitweb/?p=Mitarbeiter%2FTim-Zeitz%2Fstud-rust-base.git;a=blobdiff_plain;f=src%2Ftime.rs;h=30da0a204578347b16f1034a8fa0daf809fc6b1c;hp=2f6e9ac3b59d40235d792b5dc35a43ed45279058;hb=c56a14307218fbb51ad188826a431cd034cce473;hpb=dd14e61875eedc443d6004db819562a9b7f98a14 diff --git a/src/time.rs b/src/time.rs index 2f6e9ac..30da0a2 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,6 +1,5 @@ use time_crate as time; -#[allow(dead_code)] pub fn report_time Out>(name: &str, f: F) -> Out { let start = time::now(); println!("starting {}", name); @@ -9,36 +8,36 @@ pub fn report_time Out>(name: &str, f: F) -> Out { res } -#[allow(dead_code)] pub fn measure Out>(f: F) -> (Out, time::Duration) { let start = time::now(); let res = f(); (res, time::now() - start) } -#[allow(dead_code)] #[derive(Debug)] pub struct Timer { start: time::Tm } +impl Default for Timer { + fn default() -> Self { + Self::new() + } +} + impl Timer { - #[allow(dead_code)] pub fn new() -> Timer { Timer { start: time::now() } } - #[allow(dead_code)] pub fn restart(&mut self) { self.start = time::now(); } - #[allow(dead_code)] pub fn report_passed_ms(&self) { println!("{}ms", (time::now() - self.start).num_milliseconds()); } - #[allow(dead_code)] pub fn get_passed_ms(&self) -> i64 { (time::now() - self.start).num_milliseconds() }