opt-level 1.0.0

Get value of rustc `-Copt-level=` flag
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 22 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 98.34 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • dtolnay/opt-level
    9 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dtolnay

opt_level::OPT_LEVEL

Get the value of rustc's -Copt-level= flag at runtime.

Useful for sizing tests to run fewer iterations in slow build modes.

According to https://doc.rust-lang.org/cargo/reference/profiles.html#opt-level the possible values are:

  • 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

Example

use rand::rngs::SmallRng;
use rand::{RngCore as _, SeedableRng as _};

const N: usize = if cfg!(miri) {
    500
} else if let b"0" = opt_level::OPT_LEVEL.as_bytes() {
    10_000
} else {
    100_000_000
};

#[test]
fn random_test() {
    let mut rng = SmallRng::from_os_rng();

    for _ in 0..N {
        let bits = rng.next_u64();
        ...
        assert_eq!(..., ...);
    }
}

License