Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



But 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: