Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-06-30 10:22:20


Mathias Gaunard wrote:
> Lubomir Bourdev wrote:
>
>> (Assuming the compiler reduces a switch statement of consecutive
>> integers to constant time dispatch).
>
> That doesn't seem to be the case on the implementations I tried.

Try timing it. On modern CPUs, mispredicted branches affect the speed
considerably. If indirect calls are never predicted, a jump table may turn
out to be slower. What's even more interesting is that a plain linear search
via if( x == 0 ) { ... } else if( x == 1 ) { ... } else if... may outperform
a binary search because the branches predict better (there is a break-even
N, of course, it's just higher than what we think).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk