clock() - execution time for c function

后端 未结 1 759
星月不相逢
星月不相逢 2021-01-25 08:35

I am trying to measure the execution time of a code block in C. I have something like this in my code:

clock_t begin, end;
double time_spent;
begin = clock();
AT         


        
相关标签:
1条回答
  • 2021-01-25 09:06

    clock usually has very poor resolution, on the order of 10 milliseconds. This is most likely your problem. If you're on a POSIX system, use clock_gettime with the CLOCK_PROCESS_CPUTIME_ID clock to get a high-resolution result. Other types of systems probably have system-specific ways to achieve the same.

    0 讨论(0)
提交回复
热议问题