I try to find out the exact execution time for "for loop" with 2e6 iteritions. The following code is ran within 10ms after compiled from g++ for c++ file. People told me that is optimization code automatically done by C++ compiler so you get meaningless execution time. In other words,since there is no any output call such as printf or cout<< for variable a,b,c so the optimized code will do nothing for that "for loop" that is why I got really short program execution time in 10ms. Right ? Why they said the time result is meaningless for "for loop".
Please advise
int main(){
int max = 2e6;
int a,b,c;
// CODE YOU WANT TO TIME
int start = getMilliCount();
for (int i = 0; i < max; i++) {
a = 1234 + 5678 + i;
b = 1234 * 5678 + i;
c=1234/2+i;
}
int milliSecondsElapsed = getMilliSpan(start);
printf("\n\nElapsed time = %u milliseconds %d\n", milliSecondsElapsed,max);
return 0;
}