When is calculating or variable-reading faster?
- by Andreas Hornig
hi,
to be honest, I don't really know what the "small green men" in my cpu and compiler do, so I sometimes would like to know :).
Currently I would like to know what's faster, so that I can design my code in a more efficient way.
So for example I want to calclate something at different points in my sourcecode, when will it be faster to calculate it once and store it in a variable that's read and used for the next points it's needed and when is it faster to calculate it everytime?
I think it's depending on how "complex" and "long" the calculation is and how fast then cache is, where variables are stored, but I don't have any clue what's faster :).
Thanks for any reply to my tiny but important question!
Andreas
PS: perhaps it's important to know that I code in JAVA, but it's more a genral question.