i did some tests with pre- and post-incrementation, to figure if there are performance or power-consumption differences within the two operators on android.
i did not find any differences.
the basic thesis is well explained here: http://www.roman10.net/pre-increment-and-post-increment/
(pre is faster, because no temp-var is generated).
i learned this for c++, this website shows the c-implementation, but i was not able to figure out, how the implementation is done in android (maybe its different).
the code is used to test is
int lPlotRangeCtr = 0;
while (lPlotRangeCtr != mPlotRange){
int lTMP = ++lPlotRangeCtr;
}
this is the chunk for pre-increment, the one for post- works similar, as you can imagine.
i used the tamp var “lTMP” to make sure that the return value of the operator is assigned and the compiler does not convert the increment-operator.
so can anybody help me, how to find the implentation.
can the compiler still convert the operator, when its approved, that “lTMP” is never read?
are such statements automatically removed while compiling?
Compilers can be very smart and I wouldn’t be surprised if it optimized the variable right out. I suggest that you make it a global variable and mark it as volatile. This forces the compiler to write to it.
Having said all that, if you’re worried about the performance of x++ versus ++x then you are likely micromanaging your performance too much. Most performance gains are achieved at higher levels than this and the effect that this change will make on your program will be negligible in all but the most extreme cases.