Advertisement
AntonioVillanueva

Analyse du temps en C++ avec la bibliothèque ctime

Mar 1st, 2024
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <ctime>
  2. #include <iostream>
  3. using namespace std;
  4. #define CTRL_TIME 4
  5.  
  6. bool minuteur (double begin, double end,double ctrl){
  7.    
  8.     double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
  9.     if (ctrl <elapsed_secs){return true;}
  10.     return false;
  11.    
  12. }
  13.  
  14. void chronometre(double begin, double end) {
  15.  
  16.   double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
  17.   cout <<elapsed_secs<<endl;
  18.  
  19. }
  20.  
  21. int main (){
  22.     clock_t begin = clock();//Obtient l'heure initiale
  23.     clock_t end = clock();
  24.    
  25.     while (true){
  26.         end = clock();//Obtient l'heure actuelle
  27.         chronometre (begin, end);
  28.         if (minuteur(begin, end,CTRL_TIME)){return -1;}
  29.     }
  30.    
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement