Sunday, January 11, 2015

A Gem from Infosys Training Institute : Code Tuning Techniques


  • Use correct data types in your assignments : float x = 10 is bad - because an implicit conversion is indicated to the compiler, resulting in overhead. Do 10.0 in this case.
  • Know the data you're going to process! So, When it comes to switch statements, order the cases on the descending order of frequency.
  • Avoid multiple for loops if you can do one loop to cover both tasks.
  • Un-switching of for loops - when statements don't depend on the iteration, don't add overhead! Pull those outside.
  • Subtle : for( i=0; i <= max-1; i++) is bad - because the check does max-1 each iteration (really? aren't compilers smart enough to figure out this only needs to be done once?). In this case, change to i < max.
  • Break loop once result is known.

Around 1:25 in https://www.youtube.com/watch?v=TfqL31EzqSw

Why? Coz I wanted to know more about Java before diving into Android (I had already jumped in and come up to the surface for some air).

No comments: