Suppose this two pieces of code:
Code:
x = 1;
b = 2;
x += b + z;
if (h)
x--;
else
x++;
and:
Code:
if (h) {
x = 1;
b = 2;
x += b + z;
x --;
} else {
x = 1;
b = 2;
x += b + z;
x ++;
}
In runtime, both executes the same number of instruction, but example 2 is bigger in size, it has 11 lines of code, first one only have 7.
So althought runtime instruction are the same, is code 1 faster because the machine need to copy less execute-instruction each time? (I suppose that a so little example would unnoticiable, but a function with hundred of lines would be different)
(also I suppose a good compiler would optimize the code if correct optimization options are provided).