fork download
  1. #include <chrono>
  2. #include <thread>
  3. #include <iostream>
  4.  
  5. using std::chrono::high_resolution_clock;
  6. using std::chrono::duration_cast;
  7. using std::chrono::nanoseconds;
  8. using std::chrono::microseconds;
  9.  
  10. typedef std::chrono::high_resolution_clock myclock;
  11. typedef myclock::time_point time_point;
  12. typedef myclock::duration duration;
  13.  
  14. auto time_to_wait = microseconds(1000);
  15.  
  16. inline void doStuff()
  17. {
  18. std::this_thread::sleep_for(time_to_wait);
  19. }
  20.  
  21. int main()
  22. {
  23. time_point start, end;
  24. start = myclock::now();
  25. doStuff();
  26. end = myclock::now();
  27.  
  28. auto elapsed = duration_cast<microseconds>(end - start);
  29. std::cout << elapsed .count() << " microseconds elapsed\n";
  30. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
2053 microseconds elapsed