My question is very much related to this question but something remained unclear for me after reading that question and very good answer.
So as I understand it, the processor executing the code makes a branch prediction such that it already does the processing towards one branch in the hope that branch will be the one that needs to be executed. If it is wrong it will have to reroll some instructions which takes time. As I understand it the prediction is based on the pattern in the past.
So now my question would be: if I know for sure there will be a pattern in what the if statement will evaluate to, is that just as fast when the decision would have been made at compile time?
More specific for my case, I have a template function and I could do template specialization such that the decision is made on compile time, but in my opinion the code will be more clear if I use std:is_same
inside my function. But speed is also highly important for my application so if speed might be compromised I would still rather go for template specialization although that will be less readable/maintainable in my specific case. (I could make the template specialization more readable as well, but it's a big code (not fully written by me) and I rather not go through the whole code and change many things to make it nice again. Yes basically I'm lazy.)
(I think the question can go without MWE but if not I'll add some)