8 ms·
Replacing the switch with an array index and a jump. Compilers will compile switches to a branch tree, two-level jump table, or single-level jump table dependi
by userbinator 1y ago
Replacing the switch with an array index and a jump.
Compilers will compile switches to a branch tree, two-level jump table, or single-level jump table depending on density and optimisation options. If manually using a jump table is faster, you either have a terrible compiler or just haven't explored its optimisation settings enough.
- teo_zero 1y agoBut the compiler will always add the jump back to the top of the loop, so it's two jumps per cycle. Manual dispatch is one jump per cycle.