Create configuration conditional bench

As we did in rust-bitcoin [0] create a configuration conditional `bench`
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with `--all-features`
with a stable toolchain (currently this fails because of our use of the
`test` crate).

[0] - https://github.com/rust-bitcoin/rust-bitcoin/pull/1092
This commit is contained in:
Tobin C. Harding 2022-07-13 14:40:49 +10:00
parent 2a1c9ab4b8
commit a431edb86a
7 changed files with 18 additions and 10 deletions

View File

@ -18,7 +18,6 @@ features = [ "rand", "rand-std", "serde", "bitcoin_hashes", "recovery", "global-
rustdoc-args = ["--cfg", "docsrs"] rustdoc-args = ["--cfg", "docsrs"]
[features] [features]
unstable = ["recovery"]
default = ["std"] default = ["std"]
std = ["alloc", "secp256k1-sys/std"] std = ["alloc", "secp256k1-sys/std"]
# allow use of Secp256k1::new and related API that requires an allocator # allow use of Secp256k1::new and related API that requires an allocator

View File

@ -33,6 +33,11 @@ git config --local core.hooksPath githooks/
Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide. Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide.
### Benchmarks
We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the
bench marks use: `RUSTFLAGS='--cfg=bench' cargo +nightly bench --features=recovery`.
## Fuzzing ## Fuzzing
If you want to fuzz this library, or any library which depends on it, you will If you want to fuzz this library, or any library which depends on it, you will

View File

@ -98,9 +98,11 @@ if [ "$DO_ASAN" = true ]; then
cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully"
fi fi
# Bench
if [ "$DO_BENCH" = true ]; then # Bench if told to, only works with non-stable toolchain (nightly, beta).
cargo bench --all --features="unstable" if [ "$DO_BENCH" = true ]
then
RUSTFLAGS='--cfg=bench' cargo bench --features=recovery
fi fi
exit 0 exit 0

View File

@ -286,7 +286,7 @@ mod tests {
} }
} }
#[cfg(all(test, feature = "unstable"))] #[cfg(bench)]
mod benches { mod benches {
use test::{Bencher, black_box}; use test::{Bencher, black_box};

View File

@ -452,7 +452,7 @@ mod tests {
} }
} }
#[cfg(all(test, feature = "unstable"))] #[cfg(bench)]
mod benches { mod benches {
use rand::{thread_rng, RngCore}; use rand::{thread_rng, RngCore};
use test::{Bencher, black_box}; use test::{Bencher, black_box};

View File

@ -2433,7 +2433,7 @@ mod test {
} }
} }
#[cfg(all(test, feature = "unstable"))] #[cfg(bench)]
mod benches { mod benches {
use test::Bencher; use test::Bencher;
use std::collections::BTreeSet; use std::collections::BTreeSet;

View File

@ -155,14 +155,16 @@
#![allow(clippy::missing_safety_doc)] #![allow(clippy::missing_safety_doc)]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)] #![cfg_attr(all(not(test), not(feature = "std")), no_std)]
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
// Experimental features we need.
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(bench, feature(test))]
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
extern crate alloc; extern crate alloc;
#[cfg(any(test, feature = "std"))] #[cfg(any(test, feature = "std"))]
extern crate core; extern crate core;
#[cfg(all(test, feature = "unstable"))] #[cfg(bench)]
extern crate test; extern crate test;
#[macro_use] #[macro_use]
@ -1060,7 +1062,7 @@ mod tests {
} }
} }
#[cfg(all(test, feature = "unstable"))] #[cfg(bench)]
mod benches { mod benches {
use test::{Bencher, black_box}; use test::{Bencher, black_box};