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 checked some threads here (Testing the performance of a C++ app) and here (Timer function to provide time in nano seconds using C++), but i don't really understand how to apply it mon code ...
To make things clear : I'm not good at C++, I have never really learned the language formally but only used it several times with specific libraries. I am not even the author of the code I'm using (given to me by the professors).
My goal here is to check the time spent on each functions and globally when I execute the program on the Zedboard. The code is on Linux image on an SD card, the board booting on this image. It is using the opencv library for anImage processing application. I'm using g++ 4.6.3 as a compiler.
Thanks in advance for your answer !
You can create a simple timer class using the
<chrono>
header. Something like this:You can use it simply like this:
EDIT: On
POSIX
systems you can useclock_gettime()
if<chrono>
is not available: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<time.h>
. It's pretty simple to use but has flaws which i may explain later :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<time.h>
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.