Move timeit to stdx
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! Missing batteries for standard libraries.
|
||||
|
||||
use std::{cell::Cell, fmt};
|
||||
use std::{cell::Cell, fmt, time::Instant};
|
||||
|
||||
#[inline(always)]
|
||||
pub fn is_ci() -> bool {
|
||||
@@ -88,3 +88,17 @@ where
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub fn timeit(label: &'static str) -> impl Drop {
|
||||
struct Guard {
|
||||
label: &'static str,
|
||||
start: Instant,
|
||||
}
|
||||
|
||||
impl Drop for Guard {
|
||||
fn drop(&mut self) {
|
||||
eprintln!("{}: {:?}", self.label, self.start.elapsed())
|
||||
}
|
||||
}
|
||||
|
||||
Guard { label, start: Instant::now() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user