text: // Author:   Tong Qin               qintonguav@gmail.com
  // 	         Shaozu Cao 		    saozu.cao@connect.ust.hk
  
  #pragma once
  
  #include <ctime>
  #include <cstdlib>
  #include <chrono>
  
  class TicToc
  {
    public:
      TicToc()
      {
          tic();
      }
  
      void tic()
      {
          start = std::chrono::system_clock::now();
      }
  
      double toc()
      {
          end = std::chrono::system_clock::now();
          std::chrono::duration<double> elapsed_seconds = end - start;
          return elapsed_seconds.count() * 1000;
      }
  
    private:
      std::chrono::time_point<std::chrono::system_clock> start, end;
  };
  
  class TicTocV2
  {
  public:
      TicTocV2()
      {
          tic();
      }
  
      TicTocV2( bool _disp )
      {
          disp_ = _disp;
          tic();
      }
  
      void tic()
      {
          start = std::chrono::system_clock::now();
      }
  
      void toc( std::string _about_task )
      {
          end = std::chrono::system_clock::now();
          std::chrono::duration<double> elapsed_seconds = end - start;
          double elapsed_ms = elapsed_seconds.count() * 1000;
  
          if( disp_ )
          {
            std::cout.precision(3); // 10 for sec, 3 for ms 
            std::cout << _about_task << ": " << elapsed_ms << " msec." << std::endl;
          }
      }
  
  private:  
      std::chrono::time_point<std::chrono::system_clock> start, end;
      bool disp_ = false;
  };