The rustc compiler has 4 optimization level,just like gcc.
opt-level
This flag lets you control the optimization level.
0: no optimizations
1: basic optimizations
2: some optimizations
3: all optimizations
s: optimize for binary size
z: optimize for binary size, but also turn off loop vectorization.
如果我使用Cargo及其--release
选项进行构建,将使用哪个优化级别?
cargo build --release
Finished release [optimized] target(s) in 0.75s
答案 0 :(得分:4)
根据the cargo manual,发布版本的默认级别为-O3
。
# The release profile, used for `cargo build --release` (and the dependencies
# for `cargo test --release`, including the local library or binary).
[profile.release]
opt-level = 3
debug = false
rpath = false
lto = false
debug-assertions = false
codegen-units = 16
panic = 'unwind'
incremental = false
overflow-checks = false