2 ms·
A jump table made of function pointers has more runtime overhead than a switch-case jump table because the latter directly jumps into machine code snippets with
by flohofwoe 4y ago
A jump table made of function pointers has more runtime overhead than a switch-case jump table because the latter directly jumps into machine code snippets within the same function, and those snippets don't have the function prologues/epilogues. And function pointers are also often an "optimization barrier" where the compiler can't inline to get rid of the epilogue and prologue.
- vore 4y agoYup, though I do think in some cases if the indexes into the function table are known a sufficiently smart compiler can inline it anyway, even if the linkage isn't static: https://godbolt.org/z/6cY7zxT9W https://godbolt.org/z/6cY7zxT9W