4 ms·
Depending on the CPU, the compiler, and a whole host of other variables, a switch statement can be one of the better performing ways to write a virtual machine.
by drblast 13y ago
Depending on the CPU, the compiler, and a whole host of other variables, a switch statement can be one of the better performing ways to write a virtual machine. You certainly want to avoid the overhead of many function calls.
And if you're writing a program that does one of hundreds of things based on the value of a byte, the options for really clean code are limited, and you can do a lot worse than a huge switch statement.
Here is an interesting article on the topic:
http://www.complang.tuwien.ac.at/forth/threading/ http://www.complang.tuwien.ac.at/forth/threading/