precise time measurement

前端 未结 4 2018
甜味超标
甜味超标 2020-12-07 11:58

I\'m using time.h in C++ to measure the timing of a function.

clock_t t = clock();
someFunction();
printf(\"\\nTime taken: %.4fs\\n\", (float)(clock() - t)/         


        
4条回答
  •  渐次进展
    2020-12-07 12:05

    In C or C++ I usually do like below. If it still fails you may consider using rtdsc functions

          struct timeval time;
          gettimeofday(&time, NULL); // Start Time
    
          long totalTime = (time.tv_sec * 1000) + (time.tv_usec / 1000);
    
              //........ call your functions here
    
            gettimeofday(&time, NULL);  //END-TIME
    
            totalTime = (((time.tv_sec * 1000) + (time.tv_usec / 1000)) - totalTime);
    

提交回复
热议问题