Switch implementation

Pelle pelle.mansson at gmail.com
Tue Sep 28 12:17:17 PDT 2010


On 09/28/2010 07:33 PM, bearophile wrote:
> Through Reddit I have found a small article about reverse engineering the switch statement:
> http://www.codeproject.com/KB/cpp/switch.aspx
>
> I have compiled a test program with GCC and then with DMD with minimal changes, this is the D program and the asm from the two compilers:
>
> ... listing ...
>
> gcc and llvm-gcc use a binary search, dmd a linear one.
>
> I have done a similar interesting test (similar to switch5.cpp of the article author) where a good implementation of the switch is a small table for part of the cases and a binary tree for the other cases.
>
> Bye,
> bearophile

Interesting. Do you have any performance comparisons? The input is 
fairly small, I'm not sure a binary search will help a lot.


More information about the Digitalmars-d mailing list