Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<chrono>
- class ProcessingTime{
- public:
- ProcessingTime(const std::string& name = "Process", bool start = true) :
- m_name(name),
- m_isActive(start)
- {
- if (start)
- {
- this->restart();
- }
- }
- ~ProcessingTime()
- {
- this->stop();
- }
- ///<summary>
- ///計測のリスタート
- ///</summary>
- void restart()&
- {
- m_start = std::chrono::system_clock::now();
- m_isActive = true;
- }
- ///<summary>
- ///計測を終了し出力
- ///</summary>
- void stop()&
- {
- if (!m_isActive)
- return;
- const auto end = std::chrono::system_clock::now();
- const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds >(end - m_start).count();
- std::cout << elapsed <<"ms"<< std::endl;
- m_isActive = false;
- }
- private:
- std::string m_name;
- std::chrono::system_clock::time_point m_start;
- bool m_isActive;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement