How to check time performances in a C++ program on Zedboard

前端 未结 2 2056
离开以前
离开以前 2021-01-16 14:14

I have implemented a C++ code on a Zedboard. It compiles and runs perfectly, but now i would like to check the performances in order to optimize some functions. I have chec

2条回答
  •  臣服心动
    2021-01-16 14:58

    I have found an unsatisfying solution, but I thought I could still post it if it can be of any help.

    I made use of the gettimeofday() function defined in . It's pretty simple to use but has flaws which i may explain later :

    timeval t1, t2;
    gettimeofday(&t1, NULL);
    /* some function */
    gettimeofday(&t2, NULL);
    double time;
    time = (t2.tv_sec - t1.tv_sec)*1000.0 + (t2.tv_usec - t1.tv_usec)/1000.0; 
    cout << time << "ms" << "\n";
    

    This way I measure a time in milliseconds and display it on screen. However gettimeofday is not based on the computer clock but on the actual time. To be clear, the time elapsed between 2 calls contains indeed my function, but also all the processes running in the background on Ubuntu. In other terms, this does not give me the precise time taken by my function to execute, but a value slightly higher.

    EDIT : I found another solution again, using the clock() function from and the result seems correct in comparison of the ones i get with the previous method. Unfortunately, the precision is not enough since it gives a number in seconds with only 3 digits.

提交回复
热议问题