1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! [![github]](https://github.com/dtolnay/opt-level) [![crates-io]](https://crates.io/crates/opt-level) [![docs-rs]](https://docs.rs/opt-level)
//!
//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
//!
//! <br>
//!
//! 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, SysRng};
//! use rand::{Rng as _, SeedableRng as _};
//!
//! const N: usize = if cfg!(miri) {
//! 500
//! } else if let b"0" = opt_level::OPT_LEVEL.as_bytes() {
//! 1_000_000
//! } else {
//! 100_000_000
//! };
//!
//! # const _: &str = stringify! {
//! #[test]
//! # };
//! fn random_test() {
//! let mut rng = SmallRng::try_from_rng(&mut SysRng).unwrap();
//!
//! for _ in 0..N {
//! let bits = rng.next_u64();
//! # const _: &str = stringify! {
//! ...
//! assert_eq!(..., ...);
//! # };
//! }
//! }
//! ```
pub const OPT_LEVEL: &str = include_str!;