Advertisement
Tainel

src/base/features/timer.hpp

May 26th, 2023 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | Source Code | 0 0
  1. #pragma once
  2.  
  3. #include"base/dependencies/index.hpp"
  4.  
  5. #include"floats.hpp"
  6. #include"metaprogramming.hpp"
  7.  
  8. // Timer utility type.
  9. class timer{
  10.     // Local type aliases.
  11.     using clock=chrono::steady_clock;
  12.     using time_point=clock::time_point;
  13.     // Starting time.
  14.     static inline time_point const start=clock::now();
  15. public:
  16.     // Return the number of ticks since the starting time.
  17.     template<Float Rep=f64,class Period=ratio<1>>static Rep elapsed(){
  18.         time_point const now=clock::now();
  19.         return chrono::duration<Rep,Period>{now-start}.count();
  20.     }
  21. };
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement