It's terrible advice, period. This isn't an optimization for high performance computing, it's a waste of time you could have spent on real optimizations, with very likely no benefit whatsoever.
To give a real-world example:
Code:
const int kZero = 0;
int FnA(int x)
{
int y = 0;
if(x > 0)
y = x;
return y;
}
int FnB(int x)
{
int y = kZero;
if(x > kZero)
y = x;
return y;
}
int main(int argc, const char * argv)
{
FnA(0);
FnB(0);
return 0;
}
Compiled with
Code:
gcc -S -O0 main.cpp
to get x86_64 assembly output with no optimization, the assembly for FnA() and FnB() is:
FnA():
Code:
.globl __Z3FnAi
__Z3FnAi:
LFB2:
pushq %rbp
LCFI0:
movq %rsp, %rbp
LCFI1:
movl %edi, -20(%rbp)
movl $1, -4(%rbp)
cmpl $0, -20(%rbp)
jle L2
movl -20(%rbp), %eax
movl %eax, -4(%rbp)
L2:
movl -4(%rbp), %eax
leave
ret
FnB():
Code:
.globl __Z3FnBi
__Z3FnBi:
LFB3:
pushq %rbp
LCFI2:
movq %rsp, %rbp
LCFI3:
movl %edi, -20(%rbp)
movl $1, -4(%rbp)
cmpl $0, -20(%rbp)
jle L6
movl -20(%rbp), %eax
movl %eax, -4(%rbp)
L6:
movl -4(%rbp), %eax
leave
ret
Regardless of whether a constant or a literal is used, the actual values are encoded in the movl and cmpl instructions. The same happens with an equivalent to your own code: the comparison is done with "cmpl $9999999, -4(%rbp)", regardless of how you specify the limit. Difference in run time: precisely zero...the resulting machine code is identical. Optimization has to be disabled, of course, as the compiler will otherwise remove those loops completely, having determined that they have no effect.
Compiling as C, which has weaker support for constants and won't transform the constant to a literal, results in these two instructions instead:
Code:
movl _MaxLoop(%rip), %eax
cmpl %eax, -4(%rbp)
...which will make it slower.
Even in your example, with code that tries to maximize whatever impact there is with your compiler (in C#?), you only gain a couple percent of difference at best. This will quickly become a worthlessly small fraction of the overall run time as you add code that actually does work. That's if there's a difference in favor of your technique...in fact, if you throw out the first run (which is a clear outlier), your own measurements say that your "optimization" leads to a minor increase in execution time.