Created
May 14, 2023 22:42
-
-
Save shawnfeng0/efcf5cdda0b48844b7abc3887f8ad79e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
class Timer { | |
public: | |
Timer() { start_ = std::chrono::high_resolution_clock::now(); } | |
~Timer() = default; | |
template <typename T> | |
uint64_t elapsed() { | |
auto now = std::chrono::high_resolution_clock::now(); | |
return std::chrono::duration_cast<T>(now - start_).count(); | |
} | |
uint64_t elapsed_us() { return elapsed<std::chrono::microseconds>(); } | |
uint64_t elapsed_ms() { return elapsed<std::chrono::milliseconds>(); } | |
private: | |
std::chrono::time_point<std::chrono::high_resolution_clock> start_; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment