I have to find the time each of the function takes. Unfortunately this has to be done for many functions and the whole program comprises of 3 threads ( 1. qt thread 2. ROS thread and 3. another thread). How can this be done? Each thread has more than 1 function going being used eventually.
Also,
I tried writing a simple program to find two times. but this one is giving me a 0 all the time.
Could someone please tell me what is wrong :
#include<time.h>
#include<iostream>
using namespace std;
int main(void)
{
clock_t firstOne = clock();
cout << firstOne;
for (int i = 0; i < 10000 ; i++);
clock_t secondOne = clock();
cout << secondOne;
for (int i = 0; i < 10000 ; i++);
cout << endl << (clock() - firstOne);
cout << endl << (clock() - secondOne);
cout << endl;
}
I have to find the time each of the function takes. Unfortunately this has to be done for many functions and the whole program comprises of 3 threads ( 1. qt thread 2. ROS thread and 3. another thread). How can this be done?
Sounds like what you want is a profiler.
As for your second question, n=10000 is a very short loop. A modern desktop computer can easily finish in well under 1 millisecond. Try n=1,000,000,000.
Note that some compilers may notice that you're not doing anything in the loop and optimize it away.