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

What is the default optimization level, if I use the cargo build --release command?

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

根据 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
split-debuginfo = '...'  # Platform-specific.
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false