Fetching how long a function runs

I have a function that is running quite slowly right now and I am looking to speed it up. The first part of this though is finding out exactly how long it takes for the function to run so I can start looking at each individual part of the function to see exactly where it is taking the most time.

I am having some problems though with this. I am using the clock() function and after a bunch of searching I thought I had the solution but it still seams to be giving me invalid results. The code I have is:

1
2
3
4
5
6
7
8
9
10
11
//how long does this actually take??
clock_t start, end;
start = clock();

cout << "\t1" << endl;
//this show is a valid show and we should now get all of its episodes
_setRemoteShowEpisodes((directory + "/" + item));

end = clock();
cout << (double)(end - start) / CLOCKS_PER_SEC << " seconds. " << item << endl;
cout << "\t2" << endl << endl;


Now, just sitting and watching it go, I time it taking about 10 seconds for the function _setRemoteShowEpisodes to run. The problem though is that the time I am getting from the program is 0.04 or so seconds for that function to run.

Am I doing something really wrong or do I just not understand this clock() function?
This is one of the hardest things to do on a computer actualy, there is no "Real" way of calculating the "EXACT" speec of something, and using the wallclock wont give you the precision you need.

If you are using Windows, try QuerryPerformanceCounter();
this is more precise timer than the clock();

if you dont use windows, i dont have any clue actualy!

Hope this helps.
Tordin: :) Well, sadly no since I am programming for Linux

I understand this is difficult but the amount of time is way off so even a rough estimate is fine
Well, then... you probably need to search the Linux Kernel for some sort of super timing function, since most of them are Kernel/API Dependent.

i wish intel had an built in core for calculating cycels, that would be totaly epic.
Topic archived. No new replies allowed.