From dbd16441b8b64da7d52e51daa79357e5abeb259a Mon Sep 17 00:00:00 2001 From: zhaokuo Date: Fri, 13 Dec 2024 16:03:23 +0800 Subject: [PATCH] Reinforce gluten timer to support seconds/millseconds/microseconds --- cpp/core/utils/Timer.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cpp/core/utils/Timer.h b/cpp/core/utils/Timer.h index b6dec29b1a6a..40b5110599b8 100644 --- a/cpp/core/utils/Timer.h +++ b/cpp/core/utils/Timer.h @@ -19,11 +19,11 @@ #include -using TimePoint = std::chrono::time_point; - namespace gluten { +template class Timer { public: + using TimePoint = std::chrono::time_point; explicit Timer() = default; void start() { @@ -36,8 +36,7 @@ class Timer { return; } running_ = false; - realTimeUsed_ += - std::chrono::duration_cast(std::chrono::steady_clock::now() - startTime_).count(); + realTimeUsed_ += std::chrono::duration_cast(std::chrono::steady_clock::now() - startTime_).count(); } void reset() { @@ -62,6 +61,7 @@ class Timer { int64_t realTimeUsed_ = 0; }; +template class ScopedTimer { public: explicit ScopedTimer(int64_t* toAdd) : toAdd_(toAdd) { @@ -79,7 +79,7 @@ class ScopedTimer { } private: - Timer timer_{}; + Timer timer_{}; int64_t* toAdd_; void stopInternal() { @@ -92,4 +92,9 @@ class ScopedTimer { timer_.start(); } }; + +using ScopedSecondsTimer = ScopedTimer; +using ScopedMillisecondsTimer = ScopedTimer; +using ScopedMicrosecondsTimer = ScopedTimer; + } // namespace gluten