I’m curious if I break an expression into different declarations e.g
int x = (c / 23) % (5 *3);
int a = c /23; int b = 5 * 3; int x = a % b;
does it slow down execution, or the compiler should recognize that it can be declared into one variable. (or some other trick)
I want to know if it can be a concern to give up some readability at a performance sensitive function.
Of course, I’m not asking about this particular example, my question is about the the general rule here.
I’m using C++, but I guess is that this question can be generalized to any – at least compiled – language.
Depending on the optimization level selected for your compiler, separation into several lines of code should not matter.
You can always use the Godbolt Compiler Explorer to try and look at the resulting assembly code.
Answered By – Axel Kemper
Answer Checked By – Senaida (BugsFixing Volunteer)