Skip to content

Commit

Permalink
Add chrono unit getter
Browse files Browse the repository at this point in the history
  • Loading branch information
raultapia committed Apr 16, 2024
1 parent 8216792 commit f9767c3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/rush/chrono.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ class Chrono {
return std::chrono::duration_cast<std::chrono::duration<double, T>>(std::chrono::high_resolution_clock::now() - t0_).count();
}

/**
* @brief Get unit as string.
*
* @return Chrono unit as string.
*/
[[nodiscard]] inline std::string unit() const {
return Unit<T>().str();
}

private:
std::chrono::time_point<std::chrono::high_resolution_clock> t0_;
};
Expand All @@ -101,7 +110,7 @@ class Chronometer : public Chrono<T> {
if(!name_.empty()) {
std::cout << "[" << name_ << "] ";
}
std::cout << "Elapsed time: " << t << " " << Unit<T>().str() << std::endl;
std::cout << "Elapsed time: " << t << " " << Chrono<T>::unit() << std::endl;
}

Chronometer(const Chronometer &) = delete;
Expand Down

0 comments on commit f9767c3

Please sign in to comment.