6 ms·
It depends on your compiler. But as a general rule, the programmer will have a hard time "outsmarting" the compiler by using different objects or abstractions.
by hn_acc_2 6y ago
It depends on your compiler.
But as a general rule, the programmer will have a hard time "outsmarting" the compiler by using different objects or abstractions.
Compiler authors have spent many hundreds of combined hours making C code run as fast as possible, and optimizing the switch statement is something they've most certainly done to death.
I.e. if your control flow is switch-case-like, use a switch-case.
- Jasper_ 6y agoNot always. Computed gotos can be faster, because it can relax some restrictions that the switch statement can't amke. Most VM implementations, including CPython, use computed gotos for a not insignificant performance improvement. https://github.com/python/cpython/blob/master/Python/ceval.c#L967-L1004 https://github.com/python/cpython/blob/master/Python/ceval.c...