Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINOR] [VL] Enhance the gluten timer to support seconds, milliseconds, and microseconds #8231

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 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,13 +61,14 @@ class Timer {
int64_t realTimeUsed_ = 0;
};

class ScopedTimer {
template <typename T = std::chrono::nanoseconds>
class ScopedTimerImpl {
public:
explicit ScopedTimer(int64_t* toAdd) : toAdd_(toAdd) {
explicit ScopedTimerImpl(int64_t* toAdd) : toAdd_(toAdd) {
startInternal();
}

~ScopedTimer() {
~ScopedTimerImpl() {
stopInternal();
}

Expand All @@ -79,7 +79,7 @@ class ScopedTimer {
}

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

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

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

} // namespace gluten
Loading