3 ms·
I don't know the specifics but from the linked thread at https://bugs.python.org/issue4753 https://bugs.python.org/issue4753 : Having a jump table in itself is
by simias 11y ago
I don't know the specifics but from the linked thread at https://bugs.python.org/issue4753 https://bugs.python.org/issue4753 :
Having a jump table in itself isn't special
(the compiler does exactly that when compiling the switch() statement).
What's special is that a dedicated indirect jump instruction at the end
of each opcode helps the CPU make a separate prediction for which opcode
follows the other one, which is not possible with a switch statement
where the jump instruction is shared by all opcodes. I believe that's
where most of the speedup comes from.
So I don't think you can conclude that the compiler "probably doesn't" generate the jump table, just that you might do a better job yourself if you know what you're doing.