Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmarking is only supported by Rust nightly and therefore before this commit it was disabled by default and hidden behind `bench` feature. OTOH, declaring such feature in `Cargo.toml` would have broken `cargo +stable test --all-features`. Therefore the commit switches from using a `bench` *feature* to using a `bench` config. This commit also makes `use std:convert::TryInto` conditional via `#[cfg(debug_assertions)]`. This avoids the following build error: ``` $ RUSTFLAGS="--cfg=bench" cargo +nightly bench --all-features ... error: unused import: `std::convert::TryInto` --> src/cast.rs:1:5 | 1 | use std::convert::TryInto; | ^^^^^^^^^^^^^^^^^^^^^ ``` Additionally, this commit also opts into the `test` feature (only if the "bench" configurtaion is requested, because benchmarking is only available in the nightly version of the compiler) and declares the `extern crate test` dependency on the compiler-provided `test` crate. This avoids the following build errors: ``` $ RUSTFLAGS="--cfg=bench" cargo +nightly bench --all-features ... error[E0433]: failed to resolve: use of undeclared crate or module `test` --> src/optimize.rs:710:33 | 710 | fn bench_optimize(bencher: &mut test::Bencher) { | ^^^^ use of undeclared crate or module `test` ``` ``` $ RUSTFLAGS="--cfg=bench" cargo +nightly bench --all-features ... error[E0658]: use of unstable library feature "test" --> src/optimize.rs:710:33 | 710 | fn bench_optimize(bencher: &mut test::Bencher) { | ^^^^^^^^^^^^^ | = note: see issue #50297 <rust-lang/rust#50297> for more information = help: add `#![feature(test)]` to the crate attributes to enable ``` After these changes the following command line succeeds: ``` $ RUSTFLAGS="--cfg=bench" cargo +nightly bench --all-features ... test bits::bench_find_min_version ... bench: 1 ns/iter (+/- 0) test bits::bench_push_splitted_bytes ... bench: 3,862 ns/iter (+/- 58) test optimize::bench_optimize ... bench: 19 ns/iter (+/- 0) ```
- Loading branch information