view src/lib.rs @ 0:95fcaa3adf3b

Initial commit
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 02 Sep 2017 19:35:18 +0200
parents
children c21d8b7b61cb
line wrap: on
line source

use std::io::{self, Write};

extern crate time;

/// TestTimer allows to easily time tests. It's recommended to use the time_test!() macro.
pub struct TestTimer(time::Timespec);

impl TestTimer {
    pub fn new() -> TestTimer {
        TestTimer(time::get_time())
    }
}

impl Drop for TestTimer {
    fn drop(&mut self) {
        write!(io::stderr(), "(took {}) ", time::get_time() - self.0).is_ok();
    }
}

#[macro_export]
macro_rules! time_test {
    () => {
        use time_test::TestTimer;
        let _tt = TestTimer::new();
    }
}