vz0•

The author is only micro benchmarking an if-vs-switch with a couple of options. I imagine the positive results for the "if" alternative has more to do with data locality and CPU cache. It'd be really interesting to see a comparison with different amount of elements. Ie, 10, 100, 1000, 10000, 100000 elements.

2
[deleted]•

I would be interested to see him do the comparison again using integers instead of strings. Since he is using 2 character strings, you should be able to typecast them to a short or long integer and uses those in the switch instead. It will eliminate all the expensive string comparison operations.

1
traceawed•

Also, you should use else if() for every subsequent if statement, so that it won't have to evaluate every expression if the first is true (you could also use goto, as you essentially don't care about the rest of the if-statements)

1
[deleted]•

[deleted]

1