SHARE
TWEET

Untitled

a guest Oct 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<string>
  3. #include<chrono>
  4.  
  5. class  ProcessingTime{
  6.     public:
  7.         ProcessingTime(const std::string& name = "Process", bool start = true) :
  8.             m_name(name),
  9.             m_isActive(start)
  10.         {
  11.             if (start)
  12.             {
  13.                 this->restart();
  14.             }
  15.         }
  16.         ~ProcessingTime()
  17.         {
  18.             this->stop();
  19.         }
  20.  
  21.         ///<summary>
  22.         ///計測のリスタート
  23.         ///</summary>
  24.         void restart()&
  25.         {
  26.             m_start = std::chrono::system_clock::now();
  27.             m_isActive = true;
  28.         }
  29.         ///<summary>
  30.         ///計測を終了し出力
  31.         ///</summary>
  32.         void stop()&
  33.         {
  34.             if (!m_isActive)
  35.                 return;
  36.             const auto end = std::chrono::system_clock::now();
  37.             const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds >(end - m_start).count();
  38.             std::cout << elapsed <<"ms"<< std::endl;
  39.  
  40.             m_isActive = false;
  41.         }
  42.     private:
  43.  
  44.         std::string m_name;
  45.         std::chrono::system_clock::time_point m_start;
  46.         bool m_isActive;
  47.  
  48. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top