Thursday, 5 September 2013

fastest alternative to if-else or switch-case

fastest alternative to if-else or switch-case

I have the following definition:
typedef enum
{
def = 0,
m1 = 1,
m2 = 2,
m3 = 4,
m4 = 6,
m5 = 17,
m6 = 33,
m7 = 41,
m8 = 47,
m9 = 50,
m10 = 51,
m11 = 58,
m12 = 89,
m13 = 132,
m14 = 135
} my_enums;
And I looking for a fastest way to check if an argument to a function
falls in one of these values, m1..m14. The obvious implementation would be
if (p == m1 || p == m2 ...) or switch-case alternative.
Is there something faster? The values of m1~m14 are fixed and can't be in
contiguous range.
Thanks.

No comments:

Post a Comment