如果我使用cargo build --release命令,默认的优化级别是多少?

时间:2019-03-06 18:10:34

标签: rust rust-cargo

The rustc compiler has 4 optimization leveljust 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

1 个答案:

答案 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