mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Move timeit to stdx
This commit is contained in:
parent
72a0db8dc4
commit
1b68c72fe9
2 changed files with 15 additions and 16 deletions
|
@ -113,21 +113,6 @@ pub fn profile(label: Label) -> Profiler {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_time(label: Label) -> impl Drop {
|
|
||||||
struct Guard {
|
|
||||||
label: Label,
|
|
||||||
start: Instant,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Guard {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
eprintln!("{}: {:?}", self.label, self.start.elapsed())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Guard { label, start: Instant::now() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Profiler {
|
pub struct Profiler {
|
||||||
label: Option<Label>,
|
label: Option<Label>,
|
||||||
detail: Option<String>,
|
detail: Option<String>,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Missing batteries for standard libraries.
|
//! Missing batteries for standard libraries.
|
||||||
|
|
||||||
use std::{cell::Cell, fmt};
|
use std::{cell::Cell, fmt, time::Instant};
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_ci() -> bool {
|
pub fn is_ci() -> bool {
|
||||||
|
@ -88,3 +88,17 @@ where
|
||||||
Ok(())
|
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() }
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue