I have a program that is very time critical and I want to measure the time it takes to execute the program. Here is a simple schematic of the code.
clock1=current_time();
instruction 1;
instruction 2;
.
.
.
.
instruction n;
clock2=current_time();
total time = clock2-clock1;
When I am using GCC to compile the above code with -O2 or -O3 option it always moves clock2=current_time() in the middle of the instructions. Hence giving wrong results. Is there any way to restrict gcc not to rearrange this part of the code while optimizing all other parts of the code? Some requirements,The routine to measure time is unchangeable. I have to use the routine provided. Thank you for your help. Regards.
Update : with breakpoints
clock1=0;clock2=0;
clock1=current_time();
breakpoint 1 : instruction 1; // clock1=<value> clock2=0
instruction 2;
.
.
.
.
breakpoint 2 : instruction n;// clock1=<value> clock2=<value>
clock2=current_time();
total time = clock2-clock1;
breakpoint 3:// clock1=<value> clock2=<value> total time=clock2-clock1;