When is calculating or variable-reading faster?
Posted
by Andreas Hornig
on Stack Overflow
See other posts from Stack Overflow
or by Andreas Hornig
Published on 2010-03-16T12:22:50Z
Indexed on
2010/03/16
12:26 UTC
Read the original article
Hit count: 505
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.
© Stack Overflow or respective owner