I see in many pieces of code things like.
partial_calculation=sqrt(pow(abs(x-y))*pow(abs(x-y)));
complete_calculation1+=(partial_calculation*whatever)+something_else;
complete_calculation2+=(partial_calculation*whatever)+something_else;
complete_calculation3+=(partial_calculation*whatever)+something_else;
complete_calculation4+=(partial_calculation*whatever)+something_else;
I mean, code that makes some partial calculations and stores them in a variable and then reuses that variable to calculate some other results, when that partial calculation could have just been inlined in the next lines like so:
complete_calculation1+=(sqrt(pow(abs(x-y))*pow(abs(x-y))))*whatever)+something_else;
complete_calculation2+=(sqrt(pow(abs(x-y))*pow(abs(x-y))))*whatever)+something_else;
complete_calculation3+=(sqrt(pow(abs(x-y))*pow(abs(x-y))))*whatever)+something_else;
complete_calculation4+=(sqrt(pow(abs(x-y))*pow(abs(x-y))))*whatever)+something_else;
So i've been wondering, is this done just for clarity, or is there some benifit to the performance, because when i think of it, it kind of seems like "sqrt(pow(abs(x-y))*pow(abs(x-y)))" is going to be cached and there is no need to store it in another variable in the first place.