Skip to content

Commit a431edb

Browse files
committed
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] - rust-bitcoin/rust-bitcoin#1092
1 parent 2a1c9ab commit a431edb

File tree

7 files changed

+18
-10
lines changed

7 files changed

+18
-10
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ features = [ "rand", "rand-std", "serde", "bitcoin_hashes", "recovery", "global-
1818
rustdoc-args = ["--cfg", "docsrs"]
1919

2020
[features]
21-
unstable = ["recovery"]
2221
default = ["std"]
2322
std = ["alloc", "secp256k1-sys/std"]
2423
# allow use of Secp256k1::new and related API that requires an allocator

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ git config --local core.hooksPath githooks/
3333

3434
Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide.
3535

36+
### Benchmarks
37+
38+
We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the
39+
bench marks use: `RUSTFLAGS='--cfg=bench' cargo +nightly bench --features=recovery`.
40+
3641
## Fuzzing
3742

3843
If you want to fuzz this library, or any library which depends on it, you will

contrib/test.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ if [ "$DO_ASAN" = true ]; then
9898
cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully"
9999
fi
100100

101-
# Bench
102-
if [ "$DO_BENCH" = true ]; then
103-
cargo bench --all --features="unstable"
101+
102+
# Bench if told to, only works with non-stable toolchain (nightly, beta).
103+
if [ "$DO_BENCH" = true ]
104+
then
105+
RUSTFLAGS='--cfg=bench' cargo bench --features=recovery
104106
fi
105107

106108
exit 0

src/ecdh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ mod tests {
286286
}
287287
}
288288

289-
#[cfg(all(test, feature = "unstable"))]
289+
#[cfg(bench)]
290290
mod benches {
291291
use test::{Bencher, black_box};
292292

src/ecdsa/recovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ mod tests {
452452
}
453453
}
454454

455-
#[cfg(all(test, feature = "unstable"))]
455+
#[cfg(bench)]
456456
mod benches {
457457
use rand::{thread_rng, RngCore};
458458
use test::{Bencher, black_box};

src/key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ mod test {
24332433
}
24342434
}
24352435

2436-
#[cfg(all(test, feature = "unstable"))]
2436+
#[cfg(bench)]
24372437
mod benches {
24382438
use test::Bencher;
24392439
use std::collections::BTreeSet;

src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,16 @@
155155
#![allow(clippy::missing_safety_doc)]
156156

157157
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
158-
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
158+
159+
// Experimental features we need.
159160
#![cfg_attr(docsrs, feature(doc_cfg))]
161+
#![cfg_attr(bench, feature(test))]
160162

161163
#[cfg(feature = "alloc")]
162164
extern crate alloc;
163165
#[cfg(any(test, feature = "std"))]
164166
extern crate core;
165-
#[cfg(all(test, feature = "unstable"))]
167+
#[cfg(bench)]
166168
extern crate test;
167169

168170
#[macro_use]
@@ -1060,7 +1062,7 @@ mod tests {
10601062
}
10611063
}
10621064

1063-
#[cfg(all(test, feature = "unstable"))]
1065+
#[cfg(bench)]
10641066
mod benches {
10651067
use test::{Bencher, black_box};
10661068

0 commit comments

Comments
 (0)