C - gettimeofday for computing time?

前端 未结 5 1872
闹比i
闹比i 2020-12-08 05:13

do you know how to use gettimeofday for measuring computing time? I can measure one time by this code:

  char buffer[30];
  struct timeval tv;

  time_t curt         


        
5条回答
  •  轮回少年
    2020-12-08 05:25

    If you want to measure code efficiency, or in any other way measure time intervals, the following will be easier:

    #include 
    
    int main()
    {
       clock_t start = clock();
       //... do work here
       clock_t end = clock();
       double time_elapsed_in_seconds = (end - start)/(double)CLOCKS_PER_SEC;
       return 0;
    }
    

    hth

提交回复
热议问题