Measure execution time in C++ OpenMP code

前端 未结 5 1141
粉色の甜心
粉色の甜心 2020-11-27 05:46

I am running a .cpp code (i) in sequential style and (ii) using OpenMP statements. I am trying to see the time difference. For calculating time, I use this:

         


        
5条回答
  •  忘掉有多难
    2020-11-27 06:15

    I've seen clock() reporting CPU time, instead of real time.

    You could use

    struct timeval start, end;
    gettimeofday(&start, NULL);
    
    // benchmark code
    
    gettimeofday(&end, NULL);
    
    delta = ((end.tv_sec  - start.tv_sec) * 1000000u + 
             end.tv_usec - start.tv_usec) / 1.e6;
    

    To time things instead

提交回复
热议问题