Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

If I make a build with Cargo and its --release option, which optimization level is used?

cargo build --release
Finished release [optimized] target(s) in 0.75s
like image 920
Bence László Avatar asked Mar 06 '19 18:03

Bence László


People also ask

What does cargo build -- Release do?

cargo build --release puts the resulting binary in target/release instead of target/debug . Compiling in debug mode is the default for development-- compilation time is shorter since the compiler doesn't do optimizations, but the code will run slower. Release mode takes longer to compile, but the code will run faster.

How do you run after cargo build?

Because the default build is a debug build, Cargo puts the binary in a directory named debug. You can run the executable with this command: $ ./target/debug/hello_cargo # or .\target\debug\hello_cargo.exe on Windows Hello, world!

Where does cargo build output to?

Cargo stores the output of a build into the "target" directory. By default, this is the directory named target in the root of your workspace. To change the location, you can set the CARGO_TARGET_DIR environment variable, the build. target-dir config value, or the --target-dir command-line flag.

What does cargo run do?

When no target selection options are given, cargo run will run the binary target. If there are multiple binary targets, you must pass a target flag to choose one. Or, the default-run field may be specified in the [package] section of Cargo.


1 Answers

According to the cargo manual, the default level for release builds is -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
like image 89
apetranzilla Avatar answered Sep 23 '22 16:09

apetranzilla