I have the code:
const DEBUG_MODE: bool = false;
fn main() {
if DEBUG_MODE {
println!("In debug mode!");
}
println!("Normal code");
}
Will the Rust compiler remove the branching so it is the same as:
fn main() {
println!("Normal code");
}
Will there be any differences in the compiled assembly output?
In the case where DEBUG_MODE
is true
, will it inline the branch or will it actually do the check in assembly?
If we have a function like this:
fn debug_fn() {
if !DEBUG_MODE {
return;
}
println!("Some debug function");
}
If DEBUG_MODE
is false
, will all the calls to it be optimized out or will it still have some form of overhead?