3 ms·
Longer switches are usually compiled into binary search trees.
by deepnotderp 9y ago
Longer switches are usually compiled into binary search trees.
- fulafel 9y agoIt depends on whether the switched-on values are sparse. Contiguous ranges of bytecodes are more efficiently compiled to straight jump tables (and enable indirect branch prediction mechanisms in CPUs to work). For another boost to leveraging indirect branch prediction, threaded code is still a little better since each VM instruction has a unique jump call site: http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables http://eli.thegreenplace.net/2012/07/12/computed-goto-for-ef...
- ufo 9y agoThat blog post is from 2012. What I observed is that with the more recent processors threaded code doesn't make much of a difference.