Reputation: 741
I am trying to time a void function
for (size_t round = 0; round < 5; round++) {
cpu_time_start = get_cpu_time();
wall_time_start = get_wall_time();
scan.assign_clusters(epsilon, mu);
cpu_time_end = get_cpu_time();
wall_time_end = get_wall_time();
...
}
The first timing yields 300 seconds, while the next four timings yields 0.000002 seconds. This indicates that the void function call to assign_clusters
is optimized out. How can I force my program to execute this time consuming function call every time, and yet still use optimization for the rest of the code?
What I usually do is to save the result of the function in question and then print it, but since this is a void
function, do I have the same option?
I use the following optimization flags: -std=c++0x -march=native -O2
Upvotes: 4
Views: 261
Reputation: 13073
It depends on what is taking the time, to make the fix.
This could be caused by :-
Service starting can be a number of seconds.
Disk cache approx 20x speed up. Memory cache approx 6x speed up State caching, can be unbounded.
I think your code needs to reset the scan object, to ensure it does the work again
Upvotes: 2