void A();
void B();
void C();
void D();
void E();
void test(int i)
{
while (1)
{
final switch (i)
{
case 1: A(); break;
case 2: B(); break;
case 3: C(); break;
case 4: D(); break;
case 5: E(); break;
}
++i;
}
}
Instead of using one dispatch at the start of the loop, put the dispatch at each break;, which will produce much better branch prediction.
See also:
http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables/
Comment #1 by robert.schadek — 2024-12-13T18:22:31Z