Radfler

::measure_time

May 22nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <chrono>
  2. #include <functional>
  3. #include <utility>
  4.  
  5. template<typename Duration = std::chrono::seconds, typename Callable, typename... Args>
  6. Duration measure_time(Callable&& callable, Args&&... args) {
  7.  
  8.     using namespace std::chrono;
  9.  
  10.     auto start = high_resolution_clock::now();
  11.     std::invoke(std::forward<Callable>(callable), std::forward<Args>(args)...);
  12.     auto stop = high_resolution_clock::now();
  13.  
  14.     return duration_cast<Duration>(stop - start);
  15.  
  16. }
Add Comment
Please, Sign In to add comment