There seems to be rough equivalents of instructions to equate to the cost of a branch miss virtual functions have a similar tradeoff:  instruction vs. data cache miss  optimization barrierIf you look at something like:if (x==1) {   p->do1();}else if (x==2) {   p->do2();}else if (x==3) {   p->do3();}...You could have a member function array, or if many functions depend on the same categorization, or more complex categorization exists, use virtual functions:p->do()But, in general, how expensive are virtual functions vs branchingIt is hard to test on enough platforms to generalize, so I was wondering if any one had a rough rule of thumb (lovely if it were as simple as 4 ifs is the breakpoint)In general virtual functions are clearer and I would lean towards them.  But, I have several highly critical sections where I can change code from virtual functions to branches. I would prefer to have thoughts on this before I undertake this. (it's not a trivial change, or easy to test across multiple platforms)
In general, is it worth using virtual functions to avoid branching?
c++;performance