Consider the below code snippet:
for(i=0;i<10;i+=2) // 1
for(i=0;i<2;i=i+2) // 2
Which one will be better to use?
Does it make any difference in the performance?
Consider the below code snippet:
for(i=0;i<10;i+=2) // 1
for(i=0;i<2;i=i+2) // 2
Which one will be better to use?
Does it make any difference in the performance?
The following took 0.0260015 seconds
for (i = 0 ; i < 10000000 ; i += 2)
And this took 0.0170010
for (i = 0 ; i < 10000000 ; i = i + 2)
@MasterID is right though when I enabled 'optimize code' both reported 0.0150009 seconds
There is no definite answer to your question. It depends on how smart your compiler is among other things (optimization level, ...) and on the target platform. This is not a C language question. The language is not more or less performant by itself. It just depends on what the compiler builds out of it. So test it for your use case if performance matters at all...
Otherwise my advice, just write it in the way you feel it more readable.
The first option is as fast as the second, at least. Although any compilation optimization would generate the same assembly code.
Both express the exact same semantics, i.e. the exact same effect in the abstract machine of the C language. If one is slower than the other, it's a quality-of-implementation flaw in your compiler.