ulfben

C++: Q&D function timer

Nov 26th, 2017
997
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. template<typename Time = std::chrono::microseconds,
  2.     typename Clock = std::chrono::high_resolution_clock>
  3.     struct QuickTimer{
  4.     template<typename F, typename... Args>
  5.     static Time duration(F&& f, Args... args){
  6.         auto start = Clock::now();
  7.         std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
  8.         auto end = Clock::now();
  9.         return std::chrono::duration_cast<Time>(end - start);
  10.     }
  11. };
  12.  
  13. //Usage:
  14. using namespace std::chrono;
  15. auto t = QuickTimer<>::duration(myFunction);
  16. std::cout << duration<double, std::milli>(t).count() << "ms\n";
  17. std::cout << duration<double, std::nano>(t).count() << "ns\n";
Advertisement
Comments
  • Gyqizv
    99 days
    # text 0.21 KB | 0 0
    1. Best t33n active cpx link daily updates!
    2.  
    3. Copy and paste the link in a new browser tab and then hit enter!
    4.  
    5. https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
    6.  
    7. Remove the @
  • Yuizcko
    53 days
    # text 0.20 KB | 0 0
    1. Best Pastebin.com alternatives paste sites list
    2.  
    3. Copy and paste the link in a new browser tab and then hit enter!
    4.  
    5. https://crazyporn.xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
Add Comment
Please, Sign In to add comment