Skip to content

Commit

Permalink
Reinforce gluten timer to support seconds/millseconds/microseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
kecookier committed Dec 13, 2024
1 parent 67b6831 commit dbd1644
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cpp/core/utils/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

#include <chrono>

using TimePoint = std::chrono::time_point<std::chrono::steady_clock, std::chrono::nanoseconds>;

namespace gluten {
template <typename T = std::chrono::nanoseconds>
class Timer {
public:
using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
explicit Timer() = default;

void start() {
Expand All @@ -36,8 +36,7 @@ class Timer {
return;
}
running_ = false;
realTimeUsed_ +=
std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - startTime_).count();
realTimeUsed_ += std::chrono::duration_cast<T>(std::chrono::steady_clock::now() - startTime_).count();
}

void reset() {
Expand All @@ -62,6 +61,7 @@ class Timer {
int64_t realTimeUsed_ = 0;
};

template <typename T = std::chrono::nanoseconds>
class ScopedTimer {
public:
explicit ScopedTimer(int64_t* toAdd) : toAdd_(toAdd) {
Expand All @@ -79,7 +79,7 @@ class ScopedTimer {
}

private:
Timer timer_{};
Timer<T> timer_{};
int64_t* toAdd_;

void stopInternal() {
Expand All @@ -92,4 +92,9 @@ class ScopedTimer {
timer_.start();
}
};

using ScopedSecondsTimer = ScopedTimer<std::chrono::seconds>;
using ScopedMillisecondsTimer = ScopedTimer<std::chrono::milliseconds>;
using ScopedMicrosecondsTimer = ScopedTimer<std::chrono::microseconds>;

} // namespace gluten

0 comments on commit dbd1644

Please sign in to comment.