Easily measure elapsed time

前端 未结 26 2200
栀梦
栀梦 2020-11-22 04:13

I am trying to use time() to measure various points of my program.

What I don\'t understand is why the values in the before and after are the same? I understand thi

26条回答
  •  灰色年华
    2020-11-22 04:51

    #include 
    #include 
    
    using namespace std;
    
    void f() {
      clock_t begin = clock();
    
      // ...code to measure time...
    
      clock_t end = clock();
    
      function convtime = [](clock_t begin, clock_t end)
      {
         return double(end - begin) / CLOCKS_PER_SEC;
      };
    
      printf("Elapsed time: %.2g sec\n", convtime(begin, end));
    
    }
    

    Similar example to one available here, only with additional conversion function + print out.

提交回复
热议问题