Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #ifndef CGLIB_TIMER_H
  2. #define CGLIB_TIMER_H
  3.  
  4.  
  5. #include <chrono>
  6.  
  7.  
  8. class Timer {
  9.     std::chrono::high_resolution_clock::time_point startTime;
  10.  
  11. public:
  12.     void start() {
  13.         startTime = std::chrono::high_resolution_clock::now();
  14.     }
  15.  
  16.     bool isElapsed(double maxTimeSeconds) const {
  17.         std::chrono::duration<double> time_span = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - startTime);
  18.         return (time_span.count() >= maxTimeSeconds);
  19.     }
  20.  
  21.     double timeElapsed() const {
  22.         std::chrono::duration<double> time_span = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - startTime);
  23.         return time_span.count();
  24.     }
  25. };
  26.  
  27.  
  28. #endif //CGLIB_TIMER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement