Advertisement
Stoycho_KK

определяне колко време изисквва функция

Jan 29th, 2021
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include<iostream>
  2. #include<thread>
  3. #include<chrono>
  4.  
  5. struct Timer
  6. {
  7.     std::chrono::time_point<std::chrono::steady_clock> start, end;
  8.     std::chrono::duration<float> duration;
  9.  
  10.     Timer() {
  11.         start = std::chrono::steady_clock::now();
  12.     }
  13.  
  14.     ~Timer() {
  15.         end = std::chrono::steady_clock::now();
  16.         duration = end - start;
  17.         float output = duration.count() * 1.000f;
  18.         std::cout << "executed for: " << output << " ms"<<std::endl;
  19.     }
  20. };
  21.  
  22. void timedFunction() {
  23.     Timer time;
  24.     /*
  25.    
  26.         code
  27.            
  28.     */
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement