Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <chrono>
  4. #include <thread>
  5.  
  6. using namespace std::chrono_literals;
  7.  
  8. void testerFunction(void (foo(void))) {
  9.    
  10.     auto start = std::chrono::high_resolution_clock::now();
  11.    
  12.     foo();
  13.    
  14.     auto end = std::chrono::high_resolution_clock::now();
  15.     std::chrono::duration<double, std::milli> elapsed = end-start;
  16.    
  17.     std::cout << "Time taken: " << std::setprecision(16) << elapsed.count() << " s\n";
  18. }
  19.  
  20. // Some function
  21.  
  22. void f() {
  23.     std::this_thread::sleep_for(2s);
  24. }
  25.  
  26. int main() {
  27.    
  28.     testerFunction(f);
  29.    
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement