Code examples and code modules

How to Optimize Loops in Java MIDlets

It is more efficient to run loops so that the compare value is zero (i.e. start with the loop count and test against 0) than to start at zero and test against the final value. The reason that it is more efficient is because “compare to zero” can be contained in a single byte code. To compare against a non-zero value, on the other hand, requires several byte codes to first retrieve the final value and then to compare it to the current loop count. Analyze your loops for those that have a start count of zero and you may be able to squeeze some extra performance out of your application by reversing them so that the compare value is zero instead.

Download How to Optimize Loops in Java MIDlets (2.9 KB)