Last active
January 20, 2021 10:14
-
-
Save byBretema/3b5ba3f3aa3b73a587c4c8dc70114038 to your computer and use it in GitHub Desktop.
Timer Snippet - OOTB
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 <iostream> | |
#include <string> | |
#include <chrono> | |
using Clock = std::chrono::high_resolution_clock; | |
class Timer { | |
public: | |
Timer(std::string const & msg = "") : m_msg(msg), m_iTime(Clock::now()) {} | |
~Timer() { | |
std::cout << "[" | |
<< std::chrono::duration<double>(Clock::now() - m_iTime).count() | |
<< "s] " << m_msg << '\n'; | |
} | |
private: | |
std::string m_msg; | |
Clock::time_point m_iTime; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment