21.18 Performance of match
Expressions
Despite being more flexible than C’s switch
, Rust’s match
expressions can compile down to highly efficient code. In many cases, the compiler employs jump tables or branch trees to optimize match
at least as effectively as a series of if
-else
statements. For performance-critical code, you should still profile, but in typical situations, you can rely on match
for both readability and speed.