From 3f22799f7ba9680352588006572b481c4a2c18f8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 11 May 2025 19:48:12 +0200 Subject: [PATCH] Enhance `time!` macro for conditional compilation The `time!` macro now only logs execution time in debug mode, avoiding unnecessary overhead in release builds. Added `CommandQueueProperties` and `Context` imports to `schemsearch-ocl-matcher` for potential future functionality. --- schemsearch-common/src/lib.rs | 23 ++++++++++++++++------- schemsearch-ocl-matcher/src/lib.rs | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/schemsearch-common/src/lib.rs b/schemsearch-common/src/lib.rs index a567cb3..38da477 100644 --- a/schemsearch-common/src/lib.rs +++ b/schemsearch-common/src/lib.rs @@ -37,11 +37,20 @@ pub struct Match { #[macro_export] macro_rules! time { - ($name:ident, $body:block) => {{ - let start = std::time::Instant::now(); - let result = $body; - let duration = start.elapsed(); - println!("{} took {:?}", stringify!($name), duration); - result - }}; + ($name:ident, $body:block) => { + { + #[cfg(debug_assertions)] + { + let start = std::time::Instant::now(); + let result = $body; + let duration = start.elapsed(); + println!("{} took {:?}", stringify!($name), duration); + result + } + #[cfg(not(debug_assertions))] + { + $body + } + } + }; } diff --git a/schemsearch-ocl-matcher/src/lib.rs b/schemsearch-ocl-matcher/src/lib.rs index be6e57d..b995923 100644 --- a/schemsearch-ocl-matcher/src/lib.rs +++ b/schemsearch-ocl-matcher/src/lib.rs @@ -1,6 +1,6 @@ use math::round::ceil; use ocl::SpatialDims::Three; -use ocl::{core, Buffer, Image, MemFlags, ProQue}; +use ocl::{core, Buffer, CommandQueueProperties, Context, Image, MemFlags, ProQue}; use schemsearch_common::{time, Match, SearchBehavior}; use std::sync::OnceLock; use std::time;