From 1b68c72fe93424213db895a4066eafb99dfdeac9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 20:46:42 +0200 Subject: Move timeit to stdx --- crates/stdx/src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'crates/stdx/src') diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 401a568bd..01cdf452c 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -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() } +} -- cgit v1.2.3