I am using C# (This question is also valid for similar languages like C++) and I am trying to figure out the fastest and most efficient way to increment. It isn\'t just one
Options 1 and 2 will result in identical code being produced by the compiler. Option 3 will be much slower.
It's a fallacy that i++
is faster than i += 1
or even i = i + 1
. All decent compilers will turn those three instructions into the same code.
For such a trivial operation as addition, write the clearest code and let the compiler worry about making it fast.